![]() ![]() Constants, variables, arrays, and default settings |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() ![]() ![]() ![]() |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
General A constant can be a character string or a numerical value. The contents of a constant does not vary. A program uses a constant as defined. There are numerical constants and string constants to differentiate. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Numerical constants A numerical constant is a numeric value which can have up to 8 significant digits and the value is either positive ( "+"signed and optional ) or negative ( "-"signed ). A numerical constant cannot be greater than 1.7014118E+38 and cannot be lower than 1.548437E-38. "E" is the exponent of the base 10. The valid range of the exponent starts from -38 and ends at +38. Examples of valid numerical constants: The S-BASIC commands LIMIT, POKE, PEEK, and USR are able to use a hexadecimal constant. A hexadecimal constant is characterized by a $-sign in its first position of the constant and can have up to 4 hexadecimal digits. Examples of valid hexadecimal constants: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
String constants The contents of a string constant can contain one or more letters, numbers or any other characters. A string constant is to code between quotation marks. You cannot use a quotation mark directly within a string constant. A string constant can contain up to 255 characters. String constants can be used for example, in a PRINT command to output it on the screen or a printer. "4+9" is a string constant, it is no numerical constant and can't be used by this for computations within an arithmetical function. Examples of valid string constants: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
General
A variable is part of the work area of a program. It is used to process data with a non constant ( variable ) contents. Each variable has a symbolic name which relates to its location ( address ) in the storage. A variable contains numeric data, system data, or string data. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Numeric variables Numeric data can be stored into a numeric variable only. It contains the value 0 until it is first used by the program. The values allowed are as defined at numeric constants. The syntax of the symbolic name must be as follows: 1. The length of the name is optional. The S-BASIC identifies a variable by the first two characters only. For example, the interpreter uses A1 and A1A without distinction. 2. The first character of the name must be an alpha but not the next characters. 3. The names of a BASIC command, variable, and function are "Reserved words". This means, the use of those names are not allowed to use for the symbolic name of a variable. A list of "Reserved words" by the BASIC interpreter will follow later, but this time see the names here. All names you'll find there are reserved. Examples of valid names of numeric variables: Examples of invalid names of numeric variables: Example of the usage: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
String variables A string variable contains string data. The valid syntax of a name of a string variable is as described for numeric variables. The interpreter determines a string variable by a suffixed "$"-sign of the symbolic name. A string variable can contain up to 255 characters. It contains "null" until it will be initiated by the first usage of the program, whereby the length of it is 0. The assigned string data to a string variable must be included by quotation marks and its length determines the length of the variable. Strings can be concatenated by the "+"-sign. Examples: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
System variables A system variable is established by the interpreter itself. System variables of the S-BASIC interpreter are TI$ and SIZE. SIZE contains the actual byte size of the free storage. TI$ contains the 6 digits of the system time ( 24 hours counting ) and can be established by your program to set the clock. Further system variables are ERN and ERL. If an error occurs while the interpreter is interpreting a BASIC line of your program, ERL will contain the number of the line in error and ERN will contain the internal BASIC error number which describes the error. Examples: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
An array is a group or a table of values which can be referred to by the same name. Each value of the array is an element. The elements of an array definition are variables and can be used by any BASIC command or function. The max. numbers of elements that can be defined is depending on the available storage in most cases. The definition, the type, and the setting of the numbers of elements with its order of an array is called defining or dimensioning an array. It is done by the BASIC command DIM. Here is an example: 10 DIM C$(5) An array having one dimension only will be created by the interpreter. The array C$ has 6 elements (element #0 to element #5) and no data is assigned to these 6 elements now. Each element of these 6 elements is a string variable:
The first string variable is the first element in the array and it is called C$(0). This is another example: 20 DIM D(2,3) An array having two dimensions will be created. All elements are initiated with the value 0. Each element of an array can be referred to by the name of the array and is indicated by a number of numeric values, the index values. The number of indexes equals to the number of dimensions. The index determines the position of an element within an array. 0 is the lowest position and the max. position equals to the number given by the DIM command ( i.e. 2 and 3 ). The array D(2,3) in the example above can be imagined like a table with rows and columns:
The element of the second row and the 4th column is called D(1,3). More examples of declaring an array having one dimension: More examples of declaring an array having two dimensions: Example of declaring an array having three dimensions: Try a tiny program: 10 DIM A(2),B$(2) |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
General
The following default settings are available after the start of the S-BASIC interpreter. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Keyboard Operation mode: alphanumeric
Each function key can be defined for your own purposes. For example, to redefine key 8, that is F3+SHIFT, you code: DEF KEY(8) = "KEY LIST"+CHR$(13) and the string "CONT" is replaced with the new command which can have max. 15 characters. CHR$(13) invokes the enter key CR automatically. The command KEY LIST will list a table which contains the commands of all function keys. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
System clock TI$ will be initiated with "000000". |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Music The tempo for the PLAY command is set to 4 ( moderato, middle ) and the time is set to 5 ( 1/4 note ). |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Control characters and control key functions If you press the CTRL key coincidentally with one of the keys described in the following table, a special function will be performed as described. These keys are control keys. The associated ASCII character to the functions are also shown. These ASCII characters can be used by a PRINT command if an asterisk is suffixed to the ASCII value shown in the table and they perform the same function like pressing the associated control keys do. The addresses shown in the table are used by the S-BASIC interpreter to perform its associated subroutines. You can modify them for own purposes. Several control keys are unused (marked as NOACT in the table), but you can expand it to own functions if you want. The location address shown in the table contains the address of the interpreter's subroutine. If this address is $00E9 no function is performed, because at location $00E9 is a RET command. 16 control keys are unused and wait for your own usage.
If you use the CTRL key coincidentally with a key not shown in the table above, the last character typed in will be repeated and print on the screen. An example to activate an inactive entry: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Other default settings The boundary of the BASIC text area ( for BASIC programs ) is set to $FEFF ( LIMIT MAX ). |