DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Looping a script

Solved!
Go to solution

I have a script, that prepare test data from a channel and then shows the report. Now I want to extend the script, to be able to run multiple test datas consecutively.

My first try was making another script (from now on named script2), that gets all the Inputbox requests I have in my script for a single test (from now on named script1)and then run script1 in a for loop, as many times as chosen.

That didn't work, because script1 says the variables defined in script2 are undefined.

 

For now I've copied the code from script1 into the for loop of script2. That kind of works. I chose the file to load through a prompt at the beginning of each loop and use "looper" as the counter.

The first time the for loop gets run through no problem on the second time I get a type mismatch from here:

 

 Set ChnResult = ChnOffset("["&str(looper)&"]/Distance_filtered", "["&str(looper)&"]/Distance_filtered_Off", -Data.Root.ChannelGroups(looper).Channels("Distance_filtered").Values(Find("Ch(BrakePedalTravel) < -2")), "free offset")

 

if I comment that out, the line before that gets the Type mismatch. The line before:

 

 Set ChnResult = ChnFiltCalc("", "["&str(looper)&"]/Pitch", "["&str(looper)&"]/Pitch_filtered", "IIR", "Bessel", "Low pass", Order, MyInput, 0, 0, 1.2, 25, "Hamming", False, False) 

 

The line after:

 

Dim sFormula, aSymbol(2), aValues(2), bFormula, bValues(2), oSourceChn, oChnGroupChns, lowv, highv

 

Is there really a type mismatch? Because the first run of the loop has no problems and the problems becomes earlier if I take the error out.

0 Kudos
Message 1 of 4
(1,748 Views)

What could help is to define global variables instead of local; look at "GlobalDim" in help.

This allows you to define in script1 something (e.g. "looper") and forward its current value to the script2.

Message 2 of 4
(1,714 Views)
Solution
Accepted by topic author Nukwa

Hi Nukwa,

 

This sounds like a script structure problem. If I understand you correctly, then you have a basic functionality which should be called several times.

 

My suggestion is to create a procedure (sub or function) or a VBS class where you capsulate the basic function and call it for one or more data sets. All is defined in one script. Or – if necessary – in a second script which is called with the command ScriptInclude (more info to ScriptInclude you find in the DIAdem help).

 

Greetings

Walter

Message 3 of 4
(1,685 Views)

Thanks for the advices, GlobalDim let me use the variables, but script2 would only run once.

 

Using sub was what did it for me in the end.

0 Kudos
Message 4 of 4
(1,656 Views)