05-29-2013 03:47 AM
I am new to scripting in diadem, however have written a calculation that takes channel from a ChnComboBox in a user dialog box, this works fine however I am now wanting to repeat the calculation on a number of channels highlighted in a chnlistbox. The chnlistbox outputs to a variable "MyChn2" set as a variant, variablerowindex "1", variablecolindex "1", I have also changed the selectionmode to "1-multiple" I am struggling to understand how the "array" of channel objects is passed to my script. I have written a simple script to loop through the channels which when working I will replace the msgbox with my calculation.
For some reason after the first loop I often get an error that my indexing is wrong can any one help.
The x=1 to "3" will be the array size in the future when this is working. I am making sure I select 3 channels at the moment because of this.
My script:
call globalDim ("MyChn2()")
call globalreDim ("MyChn2(65)") 'max channels i expect to convert
If SUUDlgshow("SELECTION","SELECTION2.SUD") = "IDOk" Then
dim x
for x=1 to 3
msgbox(chnpropget(mychn2(x),"name"))
next
end if
Solved! Go to Solution.
05-29-2013 06:56 AM
I have just realised that I copied my script down incorrectly (as I work on a stand alone computer) I do actually have a "call" in front of the msgbox command.
The script does work if only one channel is selected and the MyChn2 variable is indexed to 0, but unfortunately that doesn't help me much.
Many thanks for any help.
Shuggy
06-02-2013 10:07 PM
Hi Shuggy,
What is the error DIAdem gives you on the second or later loop?
Brad Turpin
DIAdem Product Support Engineer
National Instruments
06-03-2013 06:50 AM
Brad,
The error I'm getting is
Error in <test.vbs>(line 13, Col.1)
The test variable "..CHNPROPGET(NOVALUE>,<"name").." is used as index in the
formula
CHNPROPGET(NOVALUE,"name")
This is not valid
Any help would be greatly appreciated.
Shuggy
06-03-2013 07:09 AM
Hi Shuggy,
It looks like the mychn2(x) array has some Empty or Null elements in it, so the problem would then be in the code that fills that array in the SUDialog. You can view all the elements of the array with this code line, best called right after the SUDialog ends:
MsgBox Join(mychn, vbCRLF)
Brad Turpin
DIAdem Product Support Engineer
National Instruments
06-03-2013 08:16 AM
Thanks Brad,
It seems that the ChnlistBox does not set a variable to an array but instead gives a range. The message box after using the "MsgBox Join(mychn, vbCRLF)" comand, shows only one entry:-
'[1]/2.Channel1'-'[1]/9.Channel9'
Rather than an array of the selected channels, as i had assumed. Is there a simple way to change this range into an array?
Regards
06-03-2013 10:08 AM
Hi Shuggy,
Yes, there is.
ChnArray = ChnStrToChnList(ChnStr)
Brad Turpin
DIAdem Product Support Engineer
National Instruments
06-03-2013 11:57 AM
I have nearly got this working but I'm having trouble with GlobalRedim
I use this command:
Call Globalredim(" Preserve MyChn2(chCount)")
Where chCount is the Number of channels selected.
However this does not Redim MyChn2
It works with Call GlobalRedim("Preserve MyChn2(5)")
But doen't with a variable.
Is there a way to fix this?
06-03-2013 03:09 PM
Hi Stevie,
The GlobalRedim() command takes one string parameter which you can parse with the VBScript concatenation operator "&"
Call GlobalRedim(" Preserve MyChn2(" & chCount & ")")
Brad Turpin
DIAdem Product Support Engineer
National Instruments