EnsureVariable statement

Ensures that the internal format of a Basic+ variable is coerced to the specified type.

EnsureVariable variable Is VARIABLE_TYPE

Caution: In the syntax for EnsureVariable, VARIABLE_TYPE is not quoted, although it is a literal. VARIABLE_TYPE should not be quoted. Quoting this parameter will cause compiling errors and unpredictable results.

EnsureVariable has the following parameters.

ParameterDescription
VariableA BASIC+ variable name. The name cannot be an expression.
VARIABLE_TYPESpecifies the type of data referenced by variable.

EnsureVariable is required because OpenInsight is an "untyped" language, and variables do not have specific data types, while calls to external routines require the variable to be a specific type. This is important when passing the variable contents to DLL functions - if the return value from GetPointer is being assigned to a variable, use EnsureVariable first before passing it to GetPointer.

EnsureVariable may also be necessary to control how variable comparisons are made. For example, consider comparing two Basic+ variables that contain different values in a numeric format. Due to the limitations of the numeric format when rounding, it is possible that they can appear as the same value for the purposes of the comparison. Coercing them to a string format before the comparison prevents this.

Data Types

The following table shows C data types and the corresponding OpenInsight Engine-level data types.

C data typeOpenEngine-level Data Type
CharString.
Byte, UbyteLong.
Short, UshortLong.
LongLong.
FloatDouble.
DoubleDouble.
LPVoidLong.
LPCharString.
LPByte, LPUByteLong.
LPShort, LPUShortLong.
LPLongLong.
LPDoubleDouble.
  • guides/programming/programmers_reference_manual/ensurevariable.txt
  • Last modified: 2024/10/14 18:18
  • by 127.0.0.1