DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Undertaking calculations on multiple channels using a chnlistbox

Solved!
Go to solution

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

 

 

0 Kudos
Message 1 of 9
(6,086 Views)

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

 

 

0 Kudos
Message 2 of 9
(6,078 Views)

Hi Shuggy,

 

What is the error DIAdem gives you on the second or later loop?

 

Brad Turpin

DIAdem Product Support Engineer
National Instruments

0 Kudos
Message 3 of 9
(6,051 Views)

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

0 Kudos
Message 4 of 9
(6,042 Views)

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

0 Kudos
Message 5 of 9
(6,039 Views)

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

0 Kudos
Message 6 of 9
(6,031 Views)

Hi Shuggy,

 

Yes, there is.

 

ChnArray = ChnStrToChnList(ChnStr)

 

Brad Turpin

DIAdem Product Support Engineer
National Instruments

0 Kudos
Message 7 of 9
(6,024 Views)

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?

 

 

0 Kudos
Message 8 of 9
(6,017 Views)
Solution
Accepted by topic author Shuggy1

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

0 Kudos
Message 9 of 9
(6,010 Views)