Variable names can be up to 15 alphanumeric characters long including underlines and extended characters ranging from CHR$(128) to CHR$(254). The first character may not be a number or an underline. String variable names must end with "$".
Since only the first letter of variable names are capitalized, they can be the same as a keywords which are all caps. Here are some examples of legal and illegal variable names (and why):
Variable
|
Explanation
|
Smile_1
|
legal
|
FOR
|
illegal, FOR is a keyword
|
For
|
legal with "proper" case
|
This_is_just_too_long
|
illegal, 21 chars is > 15
|
Data Types
HTBasic supports both string and numeric data types including: LONG, INTEGER, REAL, and COMPLEX. If not explicitly declared, variables are by default REAL, and if not explicitly initialized, numeric variables are set to 0 by default and strings are set to empty (""). You can force explicit declarations with CONFIGURE DIM OFF.
String is a "string" of 0-32,767 ASCII characters declared with DIM to "dimension" its maximum length (default is 18).
INTEGER is a two byte integer (whole number) ranging from -32,768 to +32,767.
LONG is a four byte integer with a range of -2,147,483,648 to 2,147,483,647.
COMPLEX consists of two REAL numbers (x + iy) where x is the real part, y the imaginary part and i is defined as the square root of -1.
REAL is an 8-byte floating point number with a range of 1E-308 to 1E+308 and 15 decimal digits of precision. MINREAL and MAXREAL are functions that return the smallest and largest REAL numbers. REAL can therefore also represent integral numbers too large to be represented by the INTEGER or LONG type numbers.
I/O Path is a special variable "type" that is "declared" with ASSIGN (to a printer, data acquisition device, string, file, etc.) and must be prefaced by @ when used in OUTPUT, ENTER and other I/O statements. However, an I/O Path variable cannot be accessed outside its normal context. For example you can't PRINT an I/O Path variable or reference it in an expression.
Examples of numeric and string constant values:
Example
|
Type of Constant
|
1, -20000
|
Integers (32,767 is max integer size)
|
&H10, &O10 or &10
|
Integer decimal 8 expressed in Hex, and Octal
|
-2121503777, 40000
|
Longs (2,147,483,647 is the max long size)
|
1.0, 3.14, +1E+0 , 6000000000
|
Reals
|
CMPLX(0,1)
|
Complex
|
"hello"
|
String
|
String Literals
A string literal is a sequence of ASCII characters enclosed in quotation marks. A quotation mark may be included in a literal by entering two adjacent quotation mark characters. For example:
DIM A$[8]
A$="""Hello"""
PRINT A$ ! prints "Hello"