Use Arrays and Array Offsets with Dynamic Associations
- Last UpdatedJul 13, 2023
- 3 minute read
Dynamic association can accept array elements or entire arrays as substitution. Passing an element of an array is achieved by referencing the element, as shown here:
AssPopUp("MyPopUp", "DigArray[42]");
To pass an entire array to a dynamic association, only the array name is used. For example:
AssPopUp("MyPopUp", "DigArray");
Use Arrays with Dynamic Associations
To pass an entire array to a dynamic association, configure it to accept the array instead of a single value. Use the following syntax for the dynamic association substitution string:
?<Data Type><Substitution String>? [<element>]
Only arrays of data type DIGITAL, INT, REAL, and LONG are supported.
Use Array Offsets with Dynamic Associations
You can use array offsets with a tag that is an array.
For example, you may have a tag (named Tag1) defined as an array of four elements. When using the GENERIC protocol, the tag has an address I1[4]:
|
Tag1 = I1[4] -> |
I1 |
|
I2 |
|
|
I3 |
|
|
I4 |
Tag1 represents the registers I1, I2, I3 and I4. When Tag1 is used with the Ass() Cicode function it behaves as follows:
-
If you associate a value using Ass(hWin, "X", "Tag1", 0) then the substitution string ?X?[0] gives the value in I1.
-
If you associate a value using Ass(hWin, "X", "Tag1", 0) then the substitution string ?X?[2] gives the value in I3.
-
If you associate a value using Ass(hWin, "X", "Tag1[0]", 0) then the substitution string ?X?[2] gives the value in I3.
-
If you associate a value using Ass(hWin, "X", "Tag1[1]", 0) then the substitution string ?X?[2] gives the value in I4. This is because the two offsets are added together to determine the final offset within the array variable.
-
If you associate a value using Ass(hWin, "X", "Tag1[2]", 0) then the substitution string ?X?[2] gives the error #ERR. This is because the sum of the two array offsets gives a position (Tag1[4]) that is outside the bounds of the array.
You can also use array offsets with a tag that is not an array.
For example, you may have a tag (named Tag2) defined as a single value. When using the GENERIC protocol, the tag has an address I1:
|
Tag2 = I1 -> |
I1 |
When Tag2 is used with the Ass() Cicode function, it behaves as follows:
-
If you associate a value using Ass(hWin, "X", "Tag2", 0) then the substitution string ?X?[0] gives the value in I1. This is because a non-array tag is equivalent to an array with one element.
-
If you associate a value using Ass(hWin, "X", "Tag2[0]", 0) then the substitution string ?X?[0] gives the value in I1. This is because a non-array tag is equivalent to an array with one element.
-
If you associate a value using Ass(hWin, "X", "Tag2", 0) then the substitution string ?X?[2] gives the notification #ERR. This is because a non-zero offset cannot be applied to a non-array tag.
-
If you associate a value using Ass(hWin, "X", "Tag2[0]", 0) then the substitution string ?X?[2] gives the notification #ERR. This is because a non-zero offset cannot be applied to a non-array tag.
-
If you associate a value using Ass(hWin, "X", "Tag2[1]", 0) then the substitution string ?X?[2] gives the notification #ERR. This is because a non-zero offset cannot be applied to a non-array tag.
-
If you associate a value using Ass(hWin, "X", "Tag2[2]", 0) then the substitution string ?X?[2] gives the notification #ERR. This is because a non-zero offset cannot be applied to a non-array tag.