05-20-2024 12:07 PM
I have the following script which exports two data channels into a single text file.
Call GlobalDim("Group_Name")
Group_Name = Data.Root.ChannelGroups(a).Properties("name").Value
Call DataFileSaveSel(autoactpath & Group_Name & ".txt", "CSV", "'[1]/[1]','[1]/[2]'", True)
However, within each row of data, the values are separated by a TAB.
How can I change this so that the values are separated by a COMMA instead?
05-31-2024 01:32 AM
Have a look at https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z000000kFCESA2&l=de-DE .
Call GlobalDim("Group_Name")
Group_Name = Data.Root.ChannelGroups(a).Properties("name").Value
FileParameters = "<filename>"&autoactpath & Group_Name & ".txt"&"</filename>"&"<delimiter>,</delimiter>"
Call DataFileSaveSel(FileParameters, "CSV", "'[1]/[1]','[1]/[2]'", True)
this should also work for DataFileSaveSel.
05-31-2024 10:20 AM
Great! Thank you for the help.
Between now and my original post, I took an alternative (and much longer) approach by creating a new channel as a string, combining each row of data with a comma in-between the values, and then exporting only the new channel as a TXT file. Here is the code written as a loop so it can handle multiple data sets:
dim a, L, Nloop 'Loop variables
a = 1 'starting group value
L = 1 'starting loop count
Nloop = Data.Root.ChannelGroups.Count 'Number of starting data sets / loops
Do While (a < (Nloop+1))
Dim Group, Ch1, Ch2, ResultChannel, iMax, i
Set Group = Data.Root.ChannelGroups(a)
Set Ch1 = Data.Root.ChannelGroups(a).Channels(1)
Set Ch2 = Data.Root.ChannelGroups(a).Channels(2)
Call GlobalDim("Ch_Name")
Ch_Name = Data.Root.ChannelGroups(a).Properties("name").Value & ".txt"
Set ResultChannel = Group.Channels.Add(Ch_Name, DataTypeString)
iMax = Data.Root.ChannelGroups(a).Channels(1).Properties("length").Value
i = 1
FOR i = 1 TO iMax
ResultChannel(i) = Ch1(i)&", "&Ch2(i)
NEXT
Call GlobalDim("Group_Name")
Group_Name = Data.Root.ChannelGroups(a).Properties("name").Value
Call DataFileSaveSel(Group_Name & ".txt", "CSV", "'[" &a& "]/" &Ch_Name& "'", True)
a = a + 1 'Use 1 to advance to the next group
Loop