NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Using the Array SetElements function

Solved!
Go to solution

Hi All,

 

I'm trying to use the Array SetElements function to set a value to specific indices within an initialized array but I cannot figure out what the syntax is for the optional parameter 2. I've tried a whole bunch that seem to make sense but always get an error. Has anyone used this function before who can let me know what the syntax to use is?

 

Thanks,

 

Nick

0 Kudos
Message 1 of 5
(4,059 Views)

Nick,

So the syntax for setting all of the elements to a value can simply be written:

SetElements( myArray,valueToSet )

To add in the optional parameter 2 and define a range is something like this:

SetElements( myArray,valueToSet, "[3..6]" )

The .. operator is analagous to a : in Matlab.

Good luck,

Chris

0 Kudos
Message 2 of 5
(4,043 Views)

Hi Chris,

 

Thanks for the reply. I think I tried this format but couldn't get it to work for non ranged elements. What would the syntax be for setting elements 1, 3, 4, 8 etc..?

 

Thanks,

 

Nick

0 Kudos
Message 3 of 5
(4,033 Views)
Solution
Accepted by topic author nickstorton

The SetElements function does not support non-contiguous ranges of elements, so there's not much point in using it if you aren't going to set the whole array or a range of elements. You can just do:

 

array[1] = 0,

array[3] = 0,

array[4] = 0,

array[8] = 0,

 

-Doug

0 Kudos
Message 4 of 5
(4,028 Views)

Hi Doug,

 

Thanks for the response, this is the workaround I have been using. It would have been so much neater the other way though. Ah well can't have it all I guess.

 

Thanks again,

 

Nick

0 Kudos
Message 5 of 5
(4,023 Views)