Browse
(440) 299-7778
Menu
(440) 299-7778
One-year parts and labor warranty30-day money-back guaranteeEnglishEspañolContact

The text of a manual · part 8 of 47

PDT 1100 Terminal Programmer's Guide: Chapter 2 Development Environment and Procedures, pages 57 to 66

Pages 57 to 66 of 413, from PDT 1100 Terminal Programmer's Guide

The original document is the PDF (3.5 MB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.

For the Symbol PDT-1100

Page 57

Basic Program Elements

Note: Do not use a single 0 (zero) as a label name since it has a special meaning in ON ERROR GOTO, ON KEY...GOSUB, and RESUME statements. !

A reserved word cannot be used by itself for a label name, but can be included within a label name as shown below. inputkey

!

A label should not start with the character string FN.

Identifiers Identifiers for the names of variables should comprise the same alphanumerics as the labels.

Rules for Naming Identifiers !

! !

!

Limit identifier length to 10 characters including periods and excluding $ (dollar sign) and % (percent sign) suffixes. All variables can contain up to 255 identifiers. A reserved word cannot be used by itself for an identifier name, but can be included within an identifier name. An identifier should not start with a numeral or the character string FN. If starting with an FN, the character string is treated as a function identifier defined by the DEF FN statement.

Examples of identifiers: a abcdef$ a1 a12345%

Reserved Words “Reserved words” are keywords to be used in statements, functions, and operators. For the list of reserved words, refer to Appendix B, Reserved Words. !

A reserved word cannot be used by itself for a label name, a variable name, or other identifiers, but can be included within them. The following identifiers, for example,

4-7

Page 58

PDT 1100 Terminal Programmer’s Guide are improper since they use reserved words input and key as is, without modification: input = 3 key = 1 !

A reserved word can be used for a data file name as shown below. OPEN “input” AS #1

4-8

Page 59

Chapter 5 Data Types Constants A constant is a data item that does not change during program execution. Constants are classified into two types: string constants and numeric constants. Constant

Example

String constants Numeric constants

“ABC”, “123” Integer constants

In decimal notation

123%, -4567

In hexadecimal notation &HFFF, &h1A2B Real constants

123.45, -67.8E3

String Constants A “string constant” is a character string enclosed in double quotation marks ("). Its length should be a maximum of 255 characters. The character string should not contain a double quotation mark (") or any control codes.

Numeric Constants Integer Constants In Decimal Notation An integer constant in decimals can be followed by a percent sign (%) or the % can be omitted. Syntax:

sign decimalnumericstring%

5-1

Page 60

PDT 1100 Terminal Programmer’s Guide

Where sign is either a plus (+) or a minus (–). The plus sign can be omitted. The valid range is from -32,768 to 32,767. Using a comma in an integer constant to mark every three digits causes a syntax error.

In Hexadecimal Notation Integer constants in hexadecimals should be formatted as shown below. Syntax:

&H hexnumericstring

The valid range is from 0h to FFFFh. Using a period in a numeric string in hexadecimals to denote a decimal point causes a syntax error.

Real Constants Real constants should be formatted as shown below. Syntax:

sign mantissa

Syntax:

sign mantissa E sign exponent

A lowercase “e” may be used instead of uppercase “ E.” mantissa is a numeric string of up to of 10 significant digits. It can include a decimal point. Using a comma in a real constant as shown below to mark every three digits causes a syntax error. 123,456 'syntax error!

5-2

Page 61

Data Types

Variables A variable is a symbolic name that refers to a unit of data storage. The contents of a variable can change during program execution.

Types of Variables According to Format Variables are classified into two types, string variables and numeric variables, each of which is subclassified into non-array and array types. Classification of Variables String variables

Non-array type Array type

Numeric variables

Example

Integer variables

One-dimensional e$(10)

Two-dimensional gh$(1,3)

Non-array type Array type

Real variables ab3$ a% One-dimensional e%(10)

Two-dimensional fg%(2,3)

Non-array type Array type a,bcd One-dimensional e(10)

Two-dimensional fg(2,3)

Declare array variables in DIM, COMMON, and DEFREG statements. The DIM statement should precede statements that access the array variable. BASIC 3.0 can handle array variables up to two-dimensional. The subscript range for an array variable is from 0 to 254.

String Variables A string variable consists of 1 through 255 characters.

Non-Array String Variables Format non-array string variables with an identifier followed by a dollar sign ($) as shown below. Syntax:

identifier$

Example:

a$,bcd123$

5-3

Page 62

PDT 1100 Terminal Programmer’s Guide

The default number of characters for a non-array string variable is 40.

Array String Variables Format array string variables with an identifier followed by a dollar sign ($) and a pair of parentheses () as shown below. Syntax:

identifier$(subscript[, subscript])

Example:

a$(2),bcd123$(1,3)

where a pair of parentheses indicates an array. The default number of characters for an array string variable is 20.

Memory Occupation A string variable occupies the memory space by (the number of characters + one) bytes, where the added one byte is used for the character count. That is, it may occupy 2 to 256 bytes. If a non-array string variable consisting of 20 characters is declared, for example, it occupies 21-byte memory space.

Numeric Variables A numeric variable occupies 2 bytes or 6 bytes of the memory space for an integer variable or a real variable, respectively.

Non-Array Integer Variables Format non-array integer variables with an identifier followed by a percentage sign (%) as shown below. Syntax:

identifier%

Example:

a%,bcd%

Array Integer Variables Format array integer variables with an identifier followed by a percentage sign (%) and a pair of parentheses () as shown below. Syntax:

identifier%(subscript[, subscript])

Example:

e%(10),fg%(2,3),h%(i%,j%)

where a pair of parentheses indicates an array.

5-4

Page 63

Data Types

Non-Array Real Variables Format non-array real variables with an identifier only as shown below. Syntax:

identifier

Example:

a,bcd

Array Real Variables Format array real variables with an identifier followed by a pair of parentheses () as shown below. Syntax:

identifier(subscript[,subscript])

Example:

e(10),fg(2,3),h(i%,j%)

where a pair of parentheses indicates an array.

Classification of Variables Work Variables Optionally declare a work variable for general use using the DIM statement. The following examples show work variables: DIM a(10),b%(5),c$(1) d=100:e%=45 FOR count% = s1% TO s2% NEXT count%

At the start of a user program, the Interpreter initializes all work variables to zero (0) or a null character string. At the end of the program, all variables will be erased. Upon execution of the DIM statement declaring an array variable, the Interpreter allocates the memory for the array variable. The declared array variable can be erased by the ERASE statement.

Common Variables A common variable is declared by the COMMON statement. It passes its value to the chained-to programs.

Register Variables A register variable is a unique non-volatile variable supported exclusively by BASIC 3.0. It retains its value (by battery backup) even after the program has terminated or the PDT 1100

5-5

Page 64

PDT 1100 Terminal Programmer’s Guide is powered off, and can store settings of programs and other values in memory. The Interpreter stores register variables in the register variables area of the memory separate from the work variables area. Like other variables, register variables are classified into two types, string variables and numeric variables, which are subclassified into non-array and array types. The format of register variables is the same as general variables. Declare register variables including nonarray register variables with DEFREG statements. BASIC 3.0 can handle array variables up to two-dimensional. When starting a user program stored in the flash ROM for the first time, the Interpreter copies the register variables into the RAM (so that both the flash ROM and RAM store the register variables). When modifying register variables, the Interpreter changes those stored in the RAM. When uploading a program file stored in the flash ROM using the XFILE statement or System Mode, the PDT 1100 uploads the program (except for the register variables in the flash ROM) with the register variables stored in the RAM.

User-defined Functions User-defined functions are classified into three types: integer functions, real functions, and character functions. All start with an FN. User-defined Function

Name Format

Integer functions

FN functionname %

Real functions

FN functionname

Character functions

FN functionname $

Define a user-defined function with the DEF FN statement.

Setting Character String Length of Character Functions A character function may return 1 through 255 characters. Note that the default character string length results in the returned value of 40 characters. If the returned value is always less than 40 characters, use the stack efficiently by setting the actual required value smaller than the default as the maximum length, because the Interpreter positions returned values on the stack during execution of user-defined functions to occupy the memory area by the maximum length size. To define a function which results in the returned value of one character, for example, describe as follows: DEF FNshort$(i%)[1]

5-6

Page 65

Data Types

If the returned value is more than 40 characters, set the actually required length. To define a function which results in the returned values of 128 characters, for example, describe as follows: DEF FNlong$(i%)[128]

Dummy Arguments and Real Arguments Dummy arguments define user-defined functions. In the example below, i% is a dummy argument. DEF FNfunc%(i%) dummy%=i%*5 END DEF

Real arguments are passed to user-defined functions when those functions are called. In the example below, 3 is a real argument. PRINT FNfunc%(3)

Type Conversion BASIC 3.0 type conversion facility converts a value of one data type into another data type during value assignment to numeric variables and operations; from a real number into an integer number by rounding off, and vice versa, depending upon the conditions. The Interpreter converts a value of a real into an integer in the following cases: ! ! ! ! !

Assignment of real expressions to integer variables Operands for an arithmetic operator MOD Operands for logical operators: AND, OR, NOT, and XOR Parameters for functions File numbers.

In the type conversion from real into integer, the allowable value range of the resulting integer is limited as shown below. If the resulting integer comes out of the limit, an execution error occurs. -32768 resultantintegervalue +32767

In assignments or operations from integer to real, the type-converted real has higher accuracy: 5-7

Page 66

PDT 1100 Terminal Programmer’s Guide

Syntax:

realvariable = integerexpression

In the above case, the Interpreter applies the type conversion to the evaluated resultant of the integer expression before assigning the real value to the real variable. Therefore, a in the following program results in the value of 184.5. a=123%*1.5

Type Conversion Examples The following examples show the type conversion from real to integer.

Assignment of Real Expressions to Integer Variables When assigning the value of the real expression (right side) to the integer variable (left side), the Interpreter carries out type conversion. Syntax:

integervariable = realexpression

Example:

b% = 123.45 where b% becomes 123.

Operands for an Arithmetic Operator MOD Before executing the MOD operation, the Interpreter converts operands into integers. Syntax:

realexpression MOD realexpression

Example:

10.5 MOD 3.4 where the result becomes identical to 11 MOD 3.

Operands for Logical Operators AND, OR, NOT, and XOR Before executing each logical operation, the Interpreter converts operands into integers. Syntax:

NOT realexpression, realexpression {AND|OR|XOR} realexpression

Example:

10.6 AND 12.45 where the result is identical to 11 AND 12.

5-8