02-23-2021 02:58 PM
Hello,
I'm very new to DIAdem, but I haven't been able to find the answer I'm looking for. I wrote a little script to find the time difference between positions. I've named this TimeToValue.VBS. It gives me a message box with the time difference. I have the dim position changed to not be used in this script so that I can use it in the next script.
Option Explicit 'Forces the explicit declaration of all the variables in a script.
Dim RowA, RowB, RowC, RowD, TimeA, TimeB, TimeC, TimeD, ElapsedAB, ElapsedAC, ElapsedAD, A, B , C, D
Dim Position, TimeSpeed
'set Position = Data.Root.ChannelGroups(1).Channels("Run4NL")
set TimeSpeed = Data.Root.ChannelGroups(1).Channels("hz100&Time")
A = 0.025
B = 5
C = 15
D = 30
RowA = PNo(Position,A)
RowB = PNo(Position,B)
RowC = PNo(Position,C)
RowD = PNo(Position,D)
TimeA = TimeSpeed(RowA)
TimeB = TimeSpeed(RowB)
TimeC = TimeSpeed(RowC)
TimeD = TimeSpeed(RowD)
ElapsedAB = TimeB - TimeA
ElapsedAC = TimeC - TimeA
ElapsedAD = TimeD - TimeA
Call MsgBox("Time from "& A & "m to "& B & "m = " & ElapsedAB & "s" & vbNewLine & "Time from "& A & "m to "& C & "m = " & ElapsedAC & "s" & vbNewLine & "Time from "& A & "m to "& D & "m = " & ElapsedAD & "s")
Now I would like to call that same script in another one and loop through multiple runs. The channels are named "Run1RL", "Run2RL" etc.
Option Explicit 'Forces the explicit declaration of all the variables in a script.
Dim I, Position
For I = 1 To 3
Set Position = Data.Root.ChannelGroups(1).Channels("Run"& I &"RL")
Call ScriptInclude("TimeToValue")
Next
All I get from this one is the Run1RL and not any of the additional runs.
Additionally how do you output a list of values after I have defined the variables in the script. Currently I go through each one on its own and manually write them down from the message box. I remember outputting variables to a list in MATLAB, but it has been a couple years since I did that.
Thanks,
Tyler
Solved! Go to Solution.
02-24-2021 03:19 PM
Hey Tyler,
I recommend that you send the elapsed time results for each Run to a row in a set of ResultChannels in a new ResultGroup. I've preserved the MsgBox output option for each row in case you still need it. I also recommend that you use a simple Sub/Function declaration in the main VBScript. You could have that Sub/Function in a different script file and ScriptInclude() it if you want, but for the purpose of this quick answer I left it all in one script. I made up a fake data set to test the script with, and I'm including that as well-- just put the TDM/TDX files in the same folder as the VBScript file.
Brad Turpin
Principal Technical Support Engineer
NI
02-25-2021 01:05 PM
Thanks Brad! That works exactly like I wanted it to and helped me figure out what to do with the data after I had a variable defined. This gives me some new vbs commands to look up too.