From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
09-24-2012 08:46 AM
I am new to DIAdem scripting language. I have TDMS has one group and several channels with type all String. How do I read the first 4 characters of each channel values and store it in new channel? Sample data file attached.
I tried for statement in the Script Window
Ch("[1]/Result") = Ch("[1]/Frame")
or
Ch("[1]/Result") = Right(Ch("[1]/Frame", 3)
All gave me error ...
Solved! Go to Solution.
09-25-2012 11:34 AM
Hi NiCoder,
You were on the right track, but you need to call that sort of expression using the ChnCalculate() command, which will take a reference to the whole channel array of values and apply the formula cell by cell through all the values in the channel array. I'm including 3 version of about the same thing. The first parses out the last 3 characters. The second parses out all characters after the first character. The third does the same as the second but creates a numeric result channel that you can use as an X axis on a graph. The double-double-quote is the escape sequence in VBScript to denote one double quote character (ASCII=34) inside of a string constant.
Call ChnCalculate("Ch(""[1]/Result"") = Right(Ch(""[1]/Frame""), 3)") Call ChnCalculate("Ch(""[1]/Result"") = Mid(Ch(""[1]/Frame""), 2)") Call ChnCalculate("Ch(""[1]/NumericResult"") = CDbl(Mid(Ch(""[1]/Frame""), 2))")
Brad Turpin
DIAdem Product Support Engineer
National Instruments
09-25-2012 12:06 PM
But it is automatic every cells in the same column at once. I want to know how go through each single cell by DIAdem scripting.
09-25-2012 02:09 PM
Hi NiCoder,
This is how you read and write individual channel values, but know that doing it value by value is much slower than doing them all with one ChnCalculate() call:
Set Group = Data.Root.ChannelGroups(1) Set FrameChannel = Group.Channels("Frame") Set ResultChannel = Group.Channels.Add("Result", DataTypeString) iMax = FrameChannel.Size FOR i = 1 TO iMax ResultChannel(i) = Right(FrameChannel(i), 3) NEXT ' i
Brad Turpin
DIAdem Product Support Engineer
National Instruments
09-28-2012 09:54 AM
How to combine all the following code into one call use ChnCalculate() function
Dim FrameStringSize
Set Group = Data.Root.ChannelGroups(1)
Set FrameChannel = Group.Channels("Frame")
Set ResultChannel = Group.Channels.Add("Result", DataTypeString)
iMax = FrameChannel.Size
FOR i = 1 TO iMax
FrameStringSize = Len(FrameChannel(i))
if (FrameStringSize = 7)
ResultChannel(i) = Right(FrameChannel(i), 3)
else if (FrameStringSize = 😎
ResultChannel(i) = Right(FrameChannel(i), 4)
End If
NEXT ' i
09-29-2012 06:15 PM
Hi NiCoder,
None of the "Frame" values in the data set you posted have more than 4 characters, so this script you posted doesn't seem to apply to that data. I had to tweak your syntax a bit to get it to run-- here it it:
Set Group = Data.Root.ChannelGroups(1) Set FrameChannel = Group.Channels("Frame") Set ResultChannel = Group.Channels.Add("Result", DataTypeString) iMax = FrameChannel.Size FOR i = 1 TO iMax FrameStringSize = Len(FrameChannel(i)) if (FrameStringSize = 7) THEN ResultChannel(i) = Right(FrameChannel(i), 3) elseif (FrameStringSize = 8) THEN ResultChannel(i) = Right(FrameChannel(i), 4) ELSE ResultChannel(i) = FrameChannel(i) End If NEXT ' i
If you submit a script and data set that make sense to gether, I'll be happy to send you an example of using the IIF() function in the ChnCalculate() expression to change a script like that above into one line of code that executes much faster.
Brad Turpin
DIAdem Product Support Engineer
National Instruments
10-01-2012 10:34 AM
Sorry, they should be column word_XX data in the same file.
10-03-2012 10:33 AM
Hello NICoder,
may be, I don't get the challenge here but wouldn't the Mid() function do the job ? From the scripts I saw, you try to copy all characters right of the 4th one, right ?
In that case the script could be something like :
Dim oGroup,oTextChannel
Data.Root.Clear
Set oGroup = Data.Root.ChannelGroups.Add("MyGroup")
Set oTextChannel = oGroup.Channels.Add("MyText",DataTypeChnString)
oTextChannel(1) = "Peter A"
oTextChannel(2) = "Paul BCD"
oTextChannel(3) = "Mary EFG"
oTextChannel(4) = "Jay"
' the following is the calculation itself. Omitting the second parameter of Mid() makes VBScript copying the "rest"
' Shorter text like "Jay" creates an empty entry which is probably what you want in this case
Call ChnCalculate("Ch(""LastCharacters"") = Mid(Ch(""MyText""),5)")