Variables

Variables are used to temporarily store data (numeric, text, etc) at run time. The data can be changed during various operations. Variables can be used as arguments of macro commands and functions.

 

Before using a variable, you must declare it (except predefined variables). Variable declaration includes type and name. Mostly used types are int (for numeric integer values), str (for strings) and double (for numeric floating-point values). Name can consist of characters A-Z, a-z, 0-9 and _, and cannot begin with digit. In the following example, we declare variable i of type int, variable S3 of type str, and variable _a of type double. Then we assign some values:

 

int i; str S3; double _a
i=5
S3="text"
_a=15.477

 

QM has 7 intrinsic variable types: byte, word, int, long, double, lpstr and str. QM also has 7 OLE types (including safe arrays) and defines several other types. More types can be defined with type and interface statements, or in type libraries. The table shows properties of intrinsic variable types, and how they are related to Visual Basic 6 and C++ variable types:

 

Type byte word int long double lpstr str
Numeric Yes Yes Yes Yes Yes    
String           Yes Yes
Integer Yes Yes Yes Yes      
Signed     Yes Yes Yes    
Size (bytes) 1 2 4 8 8 4 16 + string
Character ! @ # % ^ $ ~
Min 0 0 -2147483648 -2^63      
Max 255 65535 2147483647 2^63 - 1      
VB6 Byte Integer Long   Double Long similar to
String
C++ BYTE,
char
WORD,
short
int, long,
DWORD,
HWND
and other
4-byte types
__int64 double LPSTR,
char*
similar to
CString

 

The picture shows how variables of different types are stored in memory. Green squares represent bytes occupied by a variable of the specified type.

 

 

See also: declaration storage and scope more types of storage predefined variables user-defined types strings OLE types and other predefied types safe arrays conversions, etc.

 

Usage: expressions operators functions strings pointers