User Tools

Site Tools

한국어

cubloc:array_and_constants:index

Table of Contents

Arrays

Cubloc BASIC supports arrays of up to 2 dimensions. Each dimension can contain up to 999 items. String Array not supported.

Dim A(20) As Byte           ' Declare an array of 20 Bytes
Dim B(200) As Integer       ' Declare an array of 200 Integers
Dim C(200) As Long          ' Declare an array of 200 Longs
Dim D(20,10) As Single      ' 2-dimensional Single array (20 x 10)

Be sure to make note of how much memory is used when using multidimensional arrays.

Dim D(20,10) As Single       ' 4 * 10 * 20 = 800 Bytes of Data Memory

Constants

Constants can be used to declare a constant value (a value that cannot be changed) within the program. This essentially allows a number to be assigned a name, often improving readability and debugging of the source code.

The CONST statement can be used to declare constants in Cubloc BASIC:

Const PI As Single = 3.14159
Const WRTTIME As Byte = 10
Const MSG1 As String = "ACCESS PORT"

When the constant is not given a type, the compiler will find an appropriate type for it as shown below:

Const PI = 3.14159         ' Declare as SINGLE
Const WRTTIME = 10         ' Declare as Byte
Const MYROOM = 310         ' Declare as Integer since it’s over 255.
Const MSG1 = "ACCESS PORT" ' Declare as String

Constant Arrays

In constant arrays, the user is able to store a list of values before the program begins. A program requiring a large number of constant values can be simplified as shown below:

Const Byte DATA1 = (31, 25, 102, 34, 1, 0, 0, 0, 0, 0, 65, 64, 34)
I = 0
A = DATA1(I)         ' Store 31 in A.
I = I + 1
A = DATA1(I)        ' Store 25 in A.
Const Byte DATA1 = ("CUBLOC SYSTEMS")

String data can be stored in Byte constant arrays. Each Byte contains the ASCII code of each character in the String. In the example above, If DATA1(0) is read, the ASCII code of 'C’ is returned. Likewise if DATA1(1) is read, ASCII code of 'U’ is returned. Integer and floating point (Single) numbers can also be stored in arrays as shown below:

Const Integer DATA1 = (6000, 3000, 65500, 0, 3200)
Const Long DATA2 = (12345678, 356789, 165500, 0, 0)
Const Single DATA3 = (3.14, 0.12345, 1.5443, 0.0, 32.0)

For multiple-line constant arrays, end each line with a comma, or an underscore character as shown :

1)

Const Byte DATA1 = (31, 25, 102, 34, 1, 0, 0, 0, 0, 0, 65, 64, 34,
                    12, 123, 94, 200, 0, 123, 44, 39, 120, 239,
                    132, 13, 34, 20, 101, 123, 44, 39, 12, 39)

2)

Const Byte DATA2 = (31, 25, 102, 34, 1, 0, 65, 64, 34_
                   , 101, 123, 44, 39, 12, 39)

String constant arrays are deprecated.

Please make note of the following differences between arrays and constant arrays.

Array Constant Array
Storage Location Data Memory (SRAM) Program Memory (FLASH)
When Allocated During Program run During Download
Can be Changed Yes No
Purpose Store changing values Store constant values
When Powered OffLost Ratained

Go CUBLOC home

cubloc/array_and_constants/index.txt · Last modified: 2023/07/06 05:29 by COMFILE Technology