Example Code

Manipulating Single-Dimensional Arrays in TestStand Expressions

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • Teststand

Code and Documents

Attachment

Overview

This example demonstrates the recommended approach for manipulating array data in TestStand 

 
Note: For manipulation of multi-dimensional arrays, refer to Example: Manipulating Multi-Dimensional Arrays in TestStand Expressions

 

Description

When working with arrays, there are common operations that you may want to complete within your test sequence without the need for a code module, including:

 

  1. Initializing an array
  2. Adding elements
  3. Removing Elements
  4. Clearing all elements

 

The expression language provides functions which allow you to accomplish these tasks with one-dimensional arrays:

 

Initializing an array to a set of arbitrary values

If you have a set of values in mind for the array, you can initialize the array using a literal, for example, an array with the values {1,2,3,4}:

 

Locals.Array1D = {1,2,3,4}
This statement will overwrite any data in the property and overwrite it with the specified array.

 


Initializing an array to a single value for all elements

If you need to create an array with many elements of a single value, such as 100 elements with the value -1, the previous method would be cumbersome due to the long array literal string.  You can use the following functions to set the array size and set the value of all elements

 

SetNumElements(Locals.Array1D, 100),
SetElements(Locals.Array1D, -1)

Setting a range of elements to a single value

The SetElements function also supports specifying an array index or range of indices to set a range of values within an array:

 

SetElements(Locals.Array1D, 42, "[3..5]")

 

Adding elements at a specified index

You can add elements at a specified index using the InsertElements function:

InsertElements(Locals.Array1D, "[3]", 5)

 

Removing Elements starting at a specified index

You can delete elements of an array using the RemoveElements function.  Be sure that the number of elements you set does not exceed the size of the array

RemoveElements(Locals.Array1D, "[1]", 2)

 

Clearing all elements

You can clear an array by setting it to an empty array literal:

Locals.Array1D = {}

 

Hardware and Software Requirements

TestStand 2014 or Compatible. 

 

Steps to Implement or Execute Code

  1. Open the attached example to see the methods demonstrated in this document.
  2. Run the sequence using Execute » Run Mainsequence
  3. Observe how each statement modifies the array element.

 

 

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.