Literals, Symbols and Variables

Data can be expressed as a literal, a symbol or a variable. There are two types of data: numeric and string.

Numeric Literals

A numeric literal consists of a series of digits representing an amount. It can contain any number of digits to the left of the decimal point and up to 9 digits to the right. The unary minus sign specifies a negative value. For example, -3.4, -17000000 and -14.3375.

String Literals

A string literal consists of a set of alphanumeric characters, such as a name or address. It is represented by a set of characters enclosed in either single or double quotes. If the string includes single quotation marks (apostrophes), it must be delimited by double quotes, and vice versa. For example:

"Mr. Wilson's report"
'Test of the "GOTO" statement'

String size is only limited by the available workspace on the system.

The following are examples of valid string literals:

"ABC%123#*4AB"
'"1Q2Z"....'
"A 'literal' string"
'COMPLETED'
' '

Go to top buttonSymbols

A symbol is an identifier which is assigned a value which can be any DataBasic expression. Symbols are most commonly used to give meaningful names to literal values and can also be used to define macros. The value assigned to a symbol is set once (usually at the start of the program or subroutine); once given a value, a symbol cannot be changed.

When you compile your program, all occurrences of each symbol are replaced with the corresponding value.

Using a symbol, where appropriate, instead of a literal value or variable has the following advantages:

To define a symbol, you use the EQUATE statement. For example:

EQU LIT TO "A 'literal' string"
EQUATE MAX.COUNT TO 10

The EQUATE statement must appear before the symbol is used in the program.

Predefined Symbols

The following predefined symbols are available:

Symbol Value Description
@ACCOUNT SYSTEM(19) Account name.
@AM or @FM CHAR(254) Attribute/field mark.
@DATE DATE() System date.
@FALSE 0 (zero) Boolean false.
@IM CHAR(255) Segment/item mark.
@LEVEL SYSTEM(16) PERFORM level.
@LOGNAME SYSTEM(50) User-id.
@LPTRHIGH SYSTEM(3) Current page length as defined by the TERM command.
@LPTRWIDE SYSTEM(2) Current page width as defined by the TERM command.
@SM or @SVM CHAR(252) Subvalue mark.
@TIME TIME() System time.
@TM CHAR(251) Start of buffer/text mark.
@TRUE 1 Boolean true.
@USER SYSTEM(19) Account name.
@USER.NO SYSTEM(18) Port number.
@USERNO SYSTEM(18) Port number.
@VM CHAR(253) Value mark.
@WHO SYSTEM(19) Account name.

Note that the symbol @SM represents a subvalue mark, not a segment mark. This is for compatibility with other MultiValue systems.

Go to top buttonVariables

A variable is a named data location which is assigned a value. The value assigned to the variable may change throughout the execution of the program. Over 1,000,000 variables can be defined in a program or subroutine (the number is dependent on the available workspace).

Variables can hold the following types of data: numbers, strings, dimensioned and dynamic arrays, references to open files (file variables), references to open connections (session handles), and references to select lists and indexes (list variables).

Arrays

An array is a multi-element variable that provides a set of locations, each capable of storing a different data value. DataBasic provides two types of array: dimensioned arrays, which must be declared before use with the DIMENSION statement; and dynamic arrays, which are string variables, divided into elements by special characters.

For more details, see Introducing Arrays.

COMMON Variables

Variables used within your program are normally local to the program module. To share data between program modules, you can use common variables and arrays, declared with the COMMON statement. Using common variables in main programs and external subroutines is more efficient than passing values in argument lists.

The names used for common variables are local to the module (program or subroutine) that declares them. The same common variables can be referred to by different names in different modules. However, this is not recommended - it is best to place common variable declarations in an item that is included in every module (using the INCLUDE statement).

Common variables are stored in local or named COMMON sections. Each DataBasic program has a local common section that is shared between just the program and its subroutines - if you run another program (for instance, with the PERFORM statement), local common variables are not available to the new program. Named common sections, once initiated, persist for the duration of a logon session and are accessible to other programs, including those run with the PERFORM statement, Embedded Basic subroutines and RealWeb subroutines.

Go to top button