User Tools

Site Tools




There are 5 types of variables in Cubloc BASIC.

  • Byte : 8 bit positive number, 0 to 255
  • Integer : 16 bit positive number, 0 to 65535
  • Long : 32 bit positive/negative number (-2147483648 to +2147483647)
  • Single : 32 bit floating point number (-3.402823E+38 to 3.402823E+38)
  • String : character string, 0 TO 127 bytes

*For storing negative numbers, please use LONG or SINGLE. Use the Dim statement for declaring variables as shown below:

Dim A As Byte                  ' Declare A as Byte.
Dim B As Integer, C As Byte    ' Commas may NOT be used.
Dim ST1 As String * 12         ' Declare a String of 12 bytes.
Dim ST2 As String              ' String is 64 bytes default.
Dim AR(10) As Byte             ' Declare AR as a Byte Array.
Dim AK(10,20) As Integer       ' Declare AK as a 2-Dimensional Array


A String can be a maximum of 127 bytes in size. When the size is not declared, a default size of 64 bytes will be assumed.

Dim ST As String * 14          ' For maximum usage of 14 bytes
Dim ST2 As String              ' Set as 64 byte String variable

When declaring a String as 14 bytes, an additional byte is allocated by the processor to store a NULL terminating character. When storing “COMFILE TECHNOLOGY” in a 14 byte String, the last 4 characters (bytes) will be truncated.

Dim ST As String * 14
ST = "COMFILE TECHNOLOGY"       ' "LOGY" is not stored

In Cubloc BASIC, only the double-quote character(“) can be used for String constants and Strings; a single-quote characters (') can not be used.

ST = "COMFILE " TECHNOLOGY"           ' (") cannot be used inside the String.
ST = "COMFILE ' TECHNOLOGY"           ' (') cannot be used inside the String.
ST = "COMFILE , TECHNOLOGY"           ' (,) cannot be used inside the String.

Furthermore, Cubloc BASIC does not support character escape sequences. Use CHR(&H22) to include a double-quote character(”) in a String. Commas and single-quotes also cannot be directly declared in a String. Use CHR(&H27) to included a single-quote character (') and CHR(&H2C) to included a comma (,).

Example for printing to an LCD:

Print Chr(&H22), "COMFILE TECHNOLOGY",Chr(&H22)           ' (")
Print Chr(&H27), "COMFILE " TECHNOLOGY",Chr(&H27)         ' (') Apostrophe

Concatenate Multiple Strings

To concatenate multiple strings together, use the + operator as shown below:

Dim a1 As String * 30
Dim a2 As String * 30
a1 = "Comfile "
a2 = "Technology "
a1 = a1 + a2 + ",Inc"
Debug a1,cr

The above program will show “Comfile Technology, Inc” on the debug screen.

How to Access Individual Characters within a String

You can treat strings as a Byte array. Simply append “_A” after the name of your string variable as shown below:

Dim ST1 As String * 12        ' ST1_A Array is created at the same time.
ST1 = "123"
ST1_A(0) = ASC("A")           ' Store A in the first character of ST1.

When you declare Dim St1 as String * 12, St1_A(12) is also declared automatically by the Real-Time Operating System (RTOS). The string and the array use the same memory space. Whether you use the string or the array, you are still accessing same memory location.

The example below shows how to convert blank characters to z.

About Variable Memory Space

In the CB220 and CB280, 2KB (2048 bytes) of data memory is available. However, the memory is not dedicated entirely to variables. Some data memory is reserved for use by peripherals like the DISPLAY and the RS232 buffers. An additional 80 bytes are used for the Debug statement.

Subroutines, functions, and interrupt routines, when executing, also consume data memory, especially if they declare local variables. Of the available 2048 bytes, about 1800 bytes can be used for global variables. Space must be reserved for subroutines which may reduce the memory available for global variables. However, this can often save memory, as the local variables will be destroyed after the subroutine completes, releasing the memory to be used again.

When the user creates buffers with SET DISPLAY or OPENCOM, data memory will be consumed to allocate buffers.

Initializing Memory

In Cubloc BASIC, data memory is not cleared when powered on. The user should initialize variables or use the RamClear statement to initialize all data memory to 0. If data memory is not cleared, the values in memory could potentially be anything. If the contents of memory are to be predictable, you must either initialize each variable, or use the Ramclear statement.

In the case of battery backed-up modules, the variables will remember their values after a power cycle (powering off and on).

Go CUBLOC home

cubloc/variables/index.txt · Last modified: 2016/07/17 17:24 by COMFILE Technology