NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

How to replace(assign) a part of elements of an array in TestStand?

Solved!
Go to solution

Hello,

 

I'd like to replace or assign values to the elements of an array.

For example, I have a local variable with 6 elements, Locals.A = {1, 2, 3, 4, 5, 6},

and I'd like to make it to be {1, 2, 13, 14, 5, 6}.

As a result, I add an expression and write "Locals.A[2..3] = {13, 14}", but it failed.

Is it possible to replace a part of an array?

 

My actual question is that I want to pass the parameters of a sequence to a local variable of the MainSequence,like the attached image.

I hope I can assign the parameter(array of 5 elements) to the range from 5th to 9th element of the  Local Variable.

Could someone give me any suggestion? Thanks a lot!

 

20141001002.JPG

0 Kudos
Message 1 of 6
(7,333 Views)

Hi,

 

I felt it should be okay to do so, thus I tested with the attached sequence and it ran correctly.

The values in locals.local of MainSequence pass to the parameter of Sequence successfully.

Is there any misunderstanding regarding your problem?

0 Kudos
Message 2 of 6
(7,299 Views)

Hi, JoeyChiu,

 

Very thanks to your reply.

I'm sorry my English is not good so that it might mislead you. I'll try my best to make it clear enough for you.

After running your sequence, I can see you'd like to pass the values of the local variable to the parameter, and popup the value to ensure it works.

My question is I'd like to pass the parameter to the local variable in the mainsequence.

Since the parameter is smaller array than the local variable, I originally thought I can replace the subset of the local variable.

Maybe the above description still confuse you, let's see your sequence.

There's a local variable in the mainsequence : {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"},

and I'd like to generate an array, say {"a", "b", "c", "d", "e"}, and set this array to be the parameters by a statement : Parameters.parameter = {"a","b","c","d","e"},

 

20141002001.JPG

 

and I hope I can pass this parameter back into the mainsequence so that I add the expression Locals.local[5..9] in the value field.

 

20141002002.JPG

 

 

My goal is to make Locals.Local to be {"0", "1", "2", "3", "4", "a", "b", "c", "d", "e"}.

In other words, I'd just like to know how to assign the values of a portion of an array.

I hope I don't mix you a lot by the above descriptionSmiley Tongue

0 Kudos
Message 3 of 6
(7,290 Views)

The [n..m] notation makes a copy of those elements in a new array, so that will not work.

 

I recommend one of the following:

 

1) Pass the whole array by reference, but only update the ones you want to in the subsequence.

 

or

 

2) Make a copy of the subset of elements in a new local variable before the module call. Then pass that copy by reference into the module. Then after the module call, copy the elements back to the locations in the original array.

 

Hope this helps,

-Doug

0 Kudos
Message 4 of 6
(7,284 Views)

Hi, dug9000,

 

Thanks to your suggestion, but I do not still realize how to do itSmiley Mad

Could you give me an example?

1) "Pass the whole array by reference", do you mean I have to make the parameter and local variable to be "pass by reference"?

 

20141003001.png

 

20141003002.png

 

I tried the above setting, but it doesn't work.

If I do not use the [n..m], just set Parmaters to Locals.Local instead of Locals.Local[5..9], Locals.Local turns to be {"a", "b", "c", "d", "e"}, not {"0","1","2","3","4","a","b","c","d",e"}

 

2)"new local variable", do you mean I can create another local variable in the MainSequence for parameter passing?

If I create Locals.Local = {"0","1","2","3","4","5","6","7","8",9"} and Locals.Temp = {"","","","",""}

The parameter = {"a","b","c","d","e"} can be easily passed to the Locals.Temp. Locals.Temp = {"a","b","c","d","e"}.

But now I face the same question, how can I replace the last five elements of the Locals.Local by Locals.Temp?

Is it the only way I can do by setting

Locals.Local[5] = Locals.Temp[0],

Locals.Local[6] = Locals.Temp[1],

Locals.Local[7] = Locals.Temp[2],

Locals.Local[8] = Locals.Temp[3],

Locals.Local[9] = Locals.Temp[4]?

If the size of the array is large, it's terrible for me.

Perhaps we can use LabVIEW VI to modify the array, but I wonder if there isa better way to do this action(replace the subset of an array)?

0 Kudos
Message 5 of 6
(7,269 Views)
Solution
Accepted by topic author William1225

1) I meant pass the whole array and in the subsequence programmatically update only a subset of the elements.

 

For either 1 or 2 you would have to write a loop that interates over and updates the elements you care about. There is no simple syntax that will do what you want. You can use a loop though rather than doing an assign statement for each element.

 

-Doug

Message 6 of 6
(7,140 Views)