Action
Dimension a variable.
Syntax
DIM var AS [XRAM/IRAM] type
Remarks
Var |
Any valid variable name such as b1, i or longname. var can also be an array : ar(10) for example. |
Type |
Bit/Boolean, Byte, Word, Integer, Long, Single or String |
XRAM |
Specify XRAM to store variable in external memory |
IRAM |
Specify IRAM to store variable in internal memory (default) |
A string variable needs an additional parameter that specifies the length of the string:
Dim s As XRAM String * 10
In this case, the string can have a length of 10 characters.
Note that BITS can only be stored in internal memory.
Difference with QB
In QB you don't need to dimension each variable before you use it. In BASCOM you must dimension each variable before you use it.
Also the XRAM/IRAM options are not available in QB.
See Also
Example
'--------------------------------------------------------------
' (c) 1995-2006 MCS Electronics
'--------------------------------------------------------------
' file: DIM.BAS
' demo: DIM
'--------------------------------------------------------------
Dim B1 As Bit 'bit can be 0 or 1
Dim A As Byte 'byte range from 0-255
Dim C As Integer 'integer range from -32767 - +32768
Dim L As Long
Dim S As Single
'Assign bits
B1 = 1 'or
Set B1 'use set
'Assign bytes
A = 12
A = A + 1
'Assign integer
C = -12
C = C + 100
Print C
'Assign long
L = 12345678
Print L
'Assign single
S = 1234.567
Print S
End