AddVariable
(Engine-Level Function)
Description: | Adds a new variable to an existing module and returns its variable value. |
Warning: | This function should be used only by advanced programmers. |
Returns: | Variable |
Usage: | Script Only. |
Function Groups: | Compilation and Online Modifications, Variable |
Related to: | DeleteVariable | MakeNonShared | MakeNonPersistent | MakePersistent | MakeShared | SetDefault | SetVariableClass | SetVariableText |
Format: | AddVariable(Module, Name, Reserved, Attrib, Class, PersistentSize, VarTextSize, NumDimensions, ArrayElem, ArraySize) |
Parameters: |
Module | ||||||||||||||||||||||||||||||||||||
Required. Any expression that returns a module value. | ||||||||||||||||||||||||||||||||||||
Name | ||||||||||||||||||||||||||||||||||||
Required. Any text expression that gives the name of the new variable. | ||||||||||||||||||||||||||||||||||||
Reserved | ||||||||||||||||||||||||||||||||||||
Reserved for future use. Set to 0. | ||||||||||||||||||||||||||||||||||||
Attrib | ||||||||||||||||||||||||||||||||||||
Required. Any numeric expression giving the variable attribute bits as follows: (See: Bitwise Parameters & Operations)
A variable cannot be both persistent and temporary, since a persistent variable is stored on disk, and a temporary variable exists only while VTScada is running or until the application is recompiled. * Note: Temporary variables should be used only by advanced users, since recompiling the application destroys them. |
Class |
Required. Any numeric expression in the range 0 to 65535, giving the variable class number for the new variable. |
PersistentSize |
Required. Any numeric expression giving the number of bytes of storage allocated in the .VAL persistent variable file for this variable. For array types, set this to the byte size of the largest array element (normally 8 bytes for numeric values). For arrays containing text, enter the character length of the longest string element. Use a valid 0 if this isn't a persistent variable. |
VarTextSize |
Required. Any numeric expression giving the length of the variable declaration text in characters. This parameter is ignored for temporary variable types. |
NumDimensions |
Required. Any numeric expression that gives the number of array dimensions for the variable. NumDimensions should be "0" for a simple variable. |
ArrayElem |
Required. Any array element giving the starting element in the array. The subscript for the array may be any numeric expression. If NumDimensions is 0, ArrayElem is ignored. If NumDimensions is 1, this specifies the starting index for the array. If NumDimensions is greater than 1, this is element of an array of starting indices for each dimension of the multidimensional array. |
ArraySize |
Required. Any numeric expression specifying the size of the array. If NumDimensions is 0, ArraySize is ignored. If NumDimensions is 1, this specifies the number of elements in the array. If NumDimensions is greater than 1, this is an array of sizes for each dimension of the array. |
Comments: |
Seldom (if ever) used when adding features to modern VTScada applications. This function doesn't affect the .SRC file; it affects the expected location of items in the .SRC file. Both must be updated in unison. |
Example:
If 1 Main; [ AddVariable(Self() { Create variable as part of this module }, "MyObjectID" { Name of new variable }, 0 { Reserved }, 256 { Variable is temporary }, 0 { Class }, 0 { Variable not persistent }, 0 { no name }, 0 { }, 0 { Array starting index }, 0 { Number of elements in array }); ]
In this example, the statement creates a temporary variable with a hard-coded name.