DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Problems looping code

I have a short script that performs an analysis on an ascii file and plots a report. I am having trouble getting it to loop using a selection of multiple input files. The code works really well on a single file I just am having problems getting it to loop thru multiple file all in the same run of the script. Does anyone have any examples of this being done???
Download All
0 Kudos
Message 1 of 9
(4,554 Views)
Hey Randy,

One option is to simply add a while loop to your current code to load in multiple files. For example:

Dim continue

Call DataDelAll ' clear all DATA channels

continue = true

do while continue = true
Call FileNameGet("Any","FileRead", "*.dat") 'Dialog box for entering filename
If (DlgState = "IDOk") Then 'Close dialog box with OK
Call ASCIILOAD (FileDlgName,0)
Else
Call MsgBoxDisp("Data loading terminated!")
continue = false
End If
loop

Call FormulaCalc("Ch('Error'):= 100-('LOAD'/'Transducer'*100)")
chndim ("Error") = "%"
Call FormulaCalc ("Ch('Absolute Error'):='LOAD'-'Transducer'")
chndim ("Absolute Error") = "lbf"

Call PICLOAD("D:\data\ISX_lever_cals\layout_isx_lever.TDR") '... P
ICFILE
Call PICUPDATE()

Is this what you want to do? This code loads in multiple files and then performs the analysis. Another options would be to run through the script with each file pause on the report for a few minutes and then repeat with the next file.

I hope this helps but if it doesn't please post back with details of exactly what you want to do.

Regards,

Sarah Miracle
National Instruments
0 Kudos
Message 2 of 9
(4,554 Views)
That is a great way of doing it and is much simplier than everything that I was trying.
I am going to change it to run the analysis and plot the report to file each time.

Thanks
Randy
0 Kudos
Message 3 of 9
(4,554 Views)
I have been working with this and have it kinda working although it isn't quite what I was looking for. I was hoping to be able to select a range of file then have it run thru the analysis and plot a metafile out for each file processed.
Can this be done?

Thanks
Randy
0 Kudos
Message 4 of 9
(4,554 Views)
Hi Randy,

Here's one suggestion:

The FileNameGet function can allow the user to select multiple files if you specify the FileDlgASCIIName optional parameter. What this does is it stores the files selected in a .lst file. You can then use this file to easily iterate through your files. The example below uses what's called a serial evaluation. You can read more about this in the DIAdem help but basically if there's a .lst file in the same directory as my vbs file with the same name then I can use a special variable called UseFileList. DIAdem will automatically execute my code multiple times each time putting a different value in UseFileList.

Here's some sample code:

This will involve 2 vbs files. They must both be in the same directory.
You can call the first one anything but the second one MUST be called File.vbs. This is because it must have the same name as the .lst file which my script calls File (you could change this).

File one:

Call DataDelAll ' clear all DATA channels

Call FileNameGet("Any","FileRead", "*.txt", "",AutoActPath & "File", True) 'Dialog box for entering filename

If (DlgState = "IDOk") Then 'Close dialog box with OK
Call ScriptStart(AutoActPath & "File.vbs")
Else
Call MsgBoxDisp("Data loading terminated!")
continue = false
End If

Next File (this one must be called File.vbs)

Call ASCIILOAD (UseFileList,0)

(You can add in here code to do the analysis and load the report. This code will be repeated for every file. If you want code to only happen once put it in the first file.)

I hope this helps!!

Please let me know if you have any further questions.

Regards,

Sarah Miracle
National Instruments
0 Kudos
Message 5 of 9
(4,554 Views)
I will try this it looks exactly like what I was looking for.

Thanks again
Randy
0 Kudos
Message 6 of 9
(4,554 Views)
Sarah
I have tried the script that you gave me. I am having one little problem. When I run it it looks like it is working until it get to the section where it does the calculations then crashes due to nothing being loaded.

I traced it back to the .lst file having only the file(s) path in it.

I copied your text exactly (cut and paste) and then created a seperate script to run the analysis.

Any ideas?

Thanks for your help
Randy


Any ideas on that??
0 Kudos
Message 7 of 9
(4,554 Views)
Hey Randy,

The .lst file is supposed to only have the file paths in it. The second .vbs file uses the lst file to obtain the file paths. I would try creating something very simple and try and get it working. For example in the second vbs file try displaying the file names to make sure it's looping through them correctly.

If you're still having problems post your code so I can take a look.

Regards,

Sarah Miracle
National Instruments
0 Kudos
Message 8 of 9
(4,554 Views)
Sarah,

I have now got the script running and doing just what I wanted.
One of our Guru's here finally figured out that the version of Diadem I had did not run the FileNameGet command properly. The path was incomplete and only one path was reported. I was running 9.01 SL1 not SL1a.

Thanks for all of the help.
Randy
0 Kudos
Message 9 of 9
(4,554 Views)