Movicon Help on Line - Rel. 11.7.1301
In the Movicon Basic Scripts you can use both Movicon Real Time DB variables, which result as global variables for all the project, and Basic Script local variables which are only visible within Basic routines and which are destroyed once the Basic Script has terminated.
The project's variables (Movicon Real Time DB) can be directly used by their names or by using the "DBVariableCmdTarget" (GetVariableValue(), SetVariableValue()) functions. In cases where structure variables are used directly, the (":") colon character used for separating the variable name and the member name is no longer used and can be replaced with the ("_") underscore or (".") point characters. However, the colon character can still be used if enclosed within square brackets ([Structure:Member]). The standard colon character is used in all the basic functions which require a variable as parameter (ie. GetVariableValue(), SetVariableValue(), etc.).
For more information on sitax and use of Structure variables in the Basic script see chapter "Pointing Variables Structure".
|
It is not possible to directly use the name of variables declared in the project's Real Time DB which start with a number or an underscore ("_") character. The reason for this is due to the fact that the VBA interpreter does not permit variable declarations of this type and therefore in cases such as these it is necessary to always use the GetVariableValue(), SetVariableValue()) functions. |
|
The variables internal Basic Scripts have priority over those of the project's. Meaning that when using the name of a project variable directly in the basic script code where a variable already exists with the same name, this will be ignored and the already existing one will be set or read. In this case you will have to use the GetVariableValue(), SetVariableValue() basic functions. |
Bit type variables, when used directly with their name, are converted into boolean (true or false). This means that a project variable with value "1" will be read as a "true" variable inside the Basic Script and therefore with a numeric value equal to "-1". The "0" value is interpreted as "false" by the Basic Script which will always be a numeric value equal to "0". This mechanism also goes for both the reading and writing of bit variables inside Basic Scripts. The GetVariableValue() and SetVariableValue() basic script functions can always be used to obviate this mechanism. In this way the function's return value will always be the numeric value of the bit, "1" and "0", and not the boolean value.
Example:
When reading the bTest variable declared in the Movicon DataBase as bit and set to "1", the result will be:
Sub Main()
Debug.Print bTest 'Result = -1
Debug.Print GetVariableValue("bTest") 'Result = 1
End Sub
IntelliSense use for RealTimeDB variables
The VBA IntelliSense can be populated by the project's global variables (the RealTimeDB variables). This way you can get a variable using the drop-down list that appears pressing the "Ctrl+Spacebar" and have direct access to structure's members and bytes array's elements.
Among variable properties a special option has been added, called "IntelliSense", which can be used to add the variable to the VBA IntelliSense list. The default value for this option is "disabled", but it can be enabled for all variables the user wants to be available in the VBA IntelliSense.
Bytes Array's elements and members of Structure variables, defined in the project's RealTimeDB, can be accessed (if the "IntelliSense" property has been enabled) within the basic script code by using the following syntax:
ArrayVarName.eMemberIndex (where MemberIndex starts from "0" to "array size -1". Ie. "Motor.e5" indicates the sixth "Motor" array element )
StructureVarName.MemberName
|
LIMITS: the IntelliSense does not show the screen local variables and is not populated with global variables if used in "Dynamic Properties Explorer". |
|
We suggest to enable the "IntelliSense" option only for those variables you intend to use in VBA scripts. The operation of populating the IntelliSense while opening or executing a script can be slow if the number of variables with this option enabled is large (i.e. thousands). |
Variables without sign
The WinWrap does not provide the use of variables without sign therefore in order to use a RealTimeDB WORD variable type (without sign) in the Basic Script it must be converted to avoid causing any overflow errors. Overflow error occur when the variable used in the script exceeds the INT type value (ie. 32767 for one Word) because the basic script engine does not manage variables without sign. To avoid this problem, a WORD type variable is always passed to the WinWrap as a Long type and a DWORD type variable is passed to the WinWrap as a "Hauge_" type which means a "64 bit integer value".
|
WORD type variables can be managed in the WinCE environment but not DWORD type (when exceeding a Long value) as WinCE does not support "VT_18" data types. |