09-19-2011 03:21 PM
Someone on my team would like to set the initial value of a multi-dimensional Array of Numbers.
What is the syntax for accomplishing this in TestStand?
09-20-2011 08:39 AM
In an expression use SetArrayBounds:
SetArrayBounds(Array array, String lowerBounds, String upperBounds)
This function changes the bounds of an array. You specify the array bounds as strings with the syntax "[x][y][z]", where x, y, and z are integer constants.
Parameter 1: The array to redimension.
Parameter 2: A string specifying the new lower bound.
Parameter 3: A string specifying the new upper bound
Returns: This function always returns 0.
Hope this helps.
-Jack
02-14-2012 06:12 PM
I've got a fairly related question so I think a bump should be ok here.
Using the TestStand Sequence Editor I create an array of numbers, call it Locals.Test. Using the IDE I change the lower bound of this array to be 1. We'll say the upper bound is 4 for the sake of the example.
If I call a Statement step type like
Locals.Test = {10,10,10,10}
the array bounds will now be 0 and 3. I just figured out I can change them back to 1 and 4 using the above mentioned SetArrayBounds....but this seems rather clunky. Any logic or reasoning with this or is this just a 'feature'?
02-15-2012 11:50 AM
The notation {10, 10, 10, 10} means to create a 1 dimensional, zero based array with those elements. You are then assigning that array to Locals.Test. Thus it is completely replacing the array in Locals.Test. It's simlar to having a Locals.foo that is zero based and assigning that to Locals.Test. Even if locals.Test was multi-dimensional or empty, the end result of that expression would be the same. Perhaps there should be a syntax for setting existing elements in an array, but that is not currently what that syntax does.
Hope this helps explain things,
-Doug
07-31-2013 10:59 AM
Thanks for your explanation, Could I trouble you for more details?
What are other pitfalls when using arrays with non standard bounds (indexed from 1 instead of 0)? I am currently trying to pass an array of booleans as a parameter to a sequence, and in the sequence editor I see the indices of [1], [2] and [3] for my one-dimensional, three element array. At runtime, I see the indices are switched back to 0,1,and 2 and I get index errors trying to acces the array with indices of 1,2,3.
it doesn't matter if I pass the array by reference or by value.
My other complaint is the documentation in the help file for the array functions, it doesn't specify types for the parameters. After adding the setarraybounds() with the properly formatted string arguments, the sequence works.
I feel like I shouldn't have to reset the bounds in an expression, having defined the array in the sequence editor already.
08-01-2013 08:54 AM - edited 08-01-2013 08:56 AM
I'm not able to reproduce the problem you are describing. Which array did you set to start at 1? The parameter or the one you are passing when calling the sequence? The parameter is just a place holder and does not affect anything, the argument you are actually passing for the parameter is the array that matters. If that argument starts at index 1 that is what you will get when you call the sequence.
If you think there is still a problem and not a misunderstanding of how things work, please let us know what version of TestStand you are using.
-Doug
08-01-2013 11:40 AM
I see, the parameter is a place holder as viewed from the Variables window when editing, and I was changing its index bounds there. While the array I actually passed through was defined by this string "{true, false, false}" in the step settings window of the sequence call step. This definition defaults to 0-indexed, and only at runtime did I see that by using the Variables window. This was my trip-up.
I guess parameter type checking verified that the array was the right size and type, but indexing is not checked.
This should help remind me to avoid using the parameter's default values, too.
Thanks for your help.
08-01-2013 02:27 PM
Yep. The dimensions for the parameter place holder can be completely different than what is passed in. The only thing checked is that the type is the same (i.e. that it's an array of the same type).
-Doug