09-18-2018 10:07 AM
I have a script that ran in DIAdem 2010 but will not run in 2018. The script has "Option Explicit" and faults on the line that contains the command Call Data.Root.Clear() with the error undefined variable. What has changed in 2018?
Solved! Go to Solution.
09-19-2018 05:42 PM
The release notes for every version of DIAdem will include a section for changes made between versions of DIAdem and could provide some more context on this.
On a related note, does this behavior show up in any other intermediate versions of DIAdem before 2018?
09-20-2018 07:35 AM
I don't know. I am new to DIAdem. I am helping our test engineer who uses it quite a bit. He had a Win 7 PC with 2010 and then made the jump to Win 10 with 2018. He still uses the script on his old Win 7 desktop that he still maintains, but is trying to set up the new Win 10 PC with 2018 and the same script.
09-20-2018 02:09 PM
Hi lhandph1,
The command you list runs fine in my DIAdem 2018 as has run fine in all versions since the Data object was introduced two versions prior to 2010. Would you please post the full VBScript file that is causing the error? Also, could you post the entire error message you're getting?
I think we're looking for a different culprit,
Brad Turpin
DIAdem Product Support Engineer
National Instruments
09-21-2018 09:32 AM
Attached is the 108C.VBS script file and a screenshot of the error message. Thanks for the help!
09-24-2018 02:33 PM
Hey handph1,
When I load your *.VBS file into the SCRIPT panel of my DIAdem 2018 and click on the "Run Script" icon at the top of the panel, that line 9 of the script runs fine. On the other hand, if I just double-click the *.VBS file in Windows Explorer, I get exactly the error message in your attached JPG file.
Are you really running this *.VBS file in DIAdem SCRIPT when you get this error message?
Brad Turpin
DIAdem Product Support Engineer
National Instruments
09-25-2018 10:04 AM
Thanks Brad. My mistake, I was running it from Windows. I loaded it into Diadem and it runs, but only with 2 files. My test engineer has 63 files to be reduced and Diadem 2010 will do that. 2018 works for only 2 files. If I try 3 or 4 files we get the error message that is attached. Any idea what would cause that? Thanks.
09-25-2018 01:31 PM
Hi lhandph1,
It's hard to pinpoint the reason for the error from the small code snippet in your attached image, but the error listed states that the ChT(row, channel) command is using a parameter that is out of bounds for the existing channels. I can confirm that the approach of using this command with numeric parameters is still valid in DIAdem 2018:
Call Data.Root.Clear Set Group = Data.Root.ChannelGroups.Add("New") Set Channel = Group.Channels.Add("StrCh", DataTypeChnString) ChT(1, 1) = "hello"
So either that channel (109) isn't long enough to accept your (b+1) row value, or the channel (109) doesn't exist, is the wrong data type, OR there is another channel in the Data Portal that is literally called "109". I know for a fact that DIAdem 2018 will latch onto a channel called "109" before it will use the 109th channel created. Earlier DIAdem versions would first look for the 109th channel if the "109" parameter had a numeric variant subtype.
Care to send any more of the code?
Brad Turpin
DIAdem Product Support Engineer
National Instruments
09-25-2018 01:47 PM
Yeah, sorry. I meant to attach the TDMS files. See attachments. If I run the script with just the step 2 and step 3 files, it does not error. if I run with all three files (step 2, step 3, step 4), I get the error.
09-27-2018 02:31 PM
Hi lhandph1,
I took the liberty of rewriting the script. If all you're doing is taking the average of each channel you load, I recommend the simple CCh() function instead of the full StatBlockCalc() command. This makes it easy to write each average value individually without needing to copy result channels. I also simplified the folder selection code, though you could further simplify it with a DirListGet() command instead of manually looping over all the files in that folder yourself. Finally, I used channel object variables instead of the brittle channel numbers. This code runs in DIAdem 2018.
OPTION EXPLICIT Dim a, aMax, StartFolderName, StartFolderPath, fname, fpath, Groups, FileChannel Dim j, jMax, AveGroup, DatGroup, AveChannels, DatChannels, AveVal, MaxGroupCount, CurGroupCount Call Data.Root.Clear() Call GetTdmsFiles(StartFolderName, StartFolderPath, fname, fpath) Data.Root.Name = StartFolderName Set Groups = Data.Root.ChannelGroups aMax = UBound(fname) FOR a = 1 TO aMax Call DataFileLoad(fpath(a), "TDMS", "Load") IF a = 1 THEN MaxGroupCount = Groups.Count Set AveGroup = Groups(MaxGroupCount) Set AveChannels = AveGroup.Channels jMax = AveChannels.Count Set FileChannel = AveGroup.Channels.Add("FileName", DataTypeString) FileChannel.Values(1) = "Channel #" END IF CurGroupCount = Groups.Count Set DatGroup = Groups(CurGroupCount) Set DatChannels = DatGroup.Channels FileChannel.Values(a+1) = fname(a) FOR j = 1 TO jMax AveVal = CCh(DatChannels(j), 0) ChnLength(AveChannels(j)) = a+1 IF a = 1 THEN AveChannels(j).Values(1) = j AveChannels(j).Values(a+1) = AveVal NEXT ' j FOR j = CurGroupCount TO MaxGroupCount+1 Step -1 Call Groups.Remove(j) NEXT ' j NEXT ' a Call Data.Move(FileChannel, AveGroup.Channels, 1) Call WndShow("VIEW") Sub GetTdmsFiles(StartFolderName, StartFolderPath, fname, fpath) Dim p, y, WSH, FLD, objFSO, objFolder, objFile Set objFSO = CreateObject("Scripting.FileSystemObject") Set WSH = CreateObject("Shell.Application") Set FLD = WSH.BrowseForFolder(0, "Select a folder", &H40 + &H1) StartFolderName = FLD.Items.Item.Name StartFolderPath = FLD.Items.Item.Path Set objFolder = objFSO.GetFolder(StartFolderPath) p = objFolder.Files.Count ReDim fpath(p) ReDim fname(p) For Each objFile in objFolder.Files If UCase(objFSO.GetExtensionName(objFile.name)) = "TDMS" Then y=y+1 fname(y) = objFile.Name fpath(y) = objFile.Path End If Next ReDim Preserve fname(y) ReDim Preserve fpath(y) End Sub ' GetTdmsFiles()
As a postscript, I really don't see the point of using the first row of each channel to store the "Channel #". You've got the channel name in the VIEW table heading, and we could easily add a channel property to show the "Channel #" in the heading. Placing this index in row 1 of each channel just makes it hard to run further calculations, such as the maximum and minimum (average) value for each channel across all the files analyzed. Still, I left the output the way it was, since I figure chances were you had other scripts or REPORT layouts that were expecting it that way.
Brad Turpin
DIAdem Product Support Engineer
National Instruments