MC-Basic:DIM ... AS LONG or DOUBLE or STRING or STRING OF UTF8

From SoftMC-Wiki
Jump to: navigation, search

This command is used to define a local variable. Local variables may be used within the PROGRAM…END PROGRAM, FUNCTION…END FUNCTION and SUB…END SUB blocks. In a PROGRAM block, the DIM command must appear after the Program keyword and before the code. In a SUB block, the DIM command must appear after the Sub keyword and before the code. Local variables are visible within the block in which they are defined.

A variable being defined may be scalar or array. An array may be defined with up to 10 dimensions. The length of a string variable is only limited by the amount of free memory space.

A local variable may be given the same name as a system or a task variable. Within the task, a reference to the variable name references the local variable and not the task or system variable.

Syntax

Dim <variable> As Long | Double | String | String of UTF8

Availability

All versions. Declaration of UTF-8 strings is available since Version 4.5.10.

Scope

Task, Multi-line commands via entry station

Limitations

Write only. Local variables cannot be used in an Event block. If they are, the program does not load, and the translation error, "Cannot use locals in event block" is given.

Examples

Program                                                      ‘Start of task

Dim local_Var1 as long                                ‘Integer
       <code>

End Program                                               ‘End of task

See Also