To satisfy the user’s customization needs, PA-20 / PA-2010 / PA-21 / PA-2110 Basic provides effective
approaches for users to generate programs right to their actual demands. This allows users to collect data,
execute data processing, then store the processed data into proper location for future use.
PA-20 / PA-2010 / PA-21 / PA-2110 Basic interpreter provides a platform for users to develop application
programs to be excuted on the PA2 series data terminals using BASIC language. Users can develop an
application to meet their own individual needs efficiently.
You’ll soon learn how to use BASIC language to write application programs. Please proceed and enjoy the
perfect combination of PA-20 / PA-2010 / PA-21 / PA-2110 Basic and PA2 series and the productivity they can
boost for you in your application.
Numeric constants include positive and negative numbers.
Numeric constants in BASIC cannot contain commas. There are
two types of numeric constants that can be used in the PT-Basic
interpreter.
Integer constants: – 2147483648 ~ + 2147483647
Real number constants: Positive or negative real number, that
contain a decimal point, such as 1.23
or –3.5897
2.2 Variables
Variable are symbols used to represent data items, such as numerical
values or character strings that are used in BASIC program. The value of a
variable may be assigned explicitly and can be changed during the
execution of the program. Value of a variable is assumed to be undefined
until a value is assigned to it.
PT-Basic Programming Manual Ver. 1.00 8/143
2.2.1 Variable Names and Declaration Characters
The following are the rules to declare variable names and
characters:
A variable name must be begun with a letter.
The remaining characters can be letters, numbers, or
underscores.
The last character can be one of these declaration characters:
DIM Str$(60) „declares a string array with 60 elements.
2.3 Expression and Operators
An expression may be a string or numeric constant, or a variable, or it may
be a combination of constants and variables with operators to produce a
string value.
Operators perform mathematical or logical operations.
PT-Basic Programming Manual Ver. 1.00 9/143
Operator
Operation
Example
^
Exponentiation
A% = 9^6
-
Negation
A% = -B%
*
Multiplication
A% = B% * C%
/
Division
A% = B% / C%
+
Addition
A% = B% + C%
-
Subtraction
A% = B% - C%
MOD
Modulo arithmetic
A% = B% MOD C%
Operator
Operation
Example
=
Equality
A% = B%
<>
Inequality
A%<> B%
>
Greater than
A% > B%
<
Less than
A%< B%
>=
Greater than or equal to
A% >= B%
<=
Less than or equal to
A% <= B%
2.3.1 Assignment Operator
PT-Basic interpreter supports an assignment operator “=”
For example:
Size% =100
PI! =3.1415
Str1$=”back”
2.3.2 Arithmetic Operator
The arithmetic operators are:
2.3.3 Relational Operator
Relational operators are used to compare two values. Result of the
comparison is either “True” or “False”.
2.3.4 Logical Operator
Logical operators perform tests on multiple relations and Boolean
operations. Logical operator returns a result which is either
“True” (not zero) or “False” (zero). In an expression, logical
PT-Basic Programming Manual Ver. 1.00 10/143
operations are performed after arithmetic and relational
operations.
Operator
Operation
Example
NOT
Logical negation
NOT (A% = B%)
AND
Logical and
(A% = B%) AND (C% =
D%)
OR
Inclusive or
(A% = B%) OR (C% = D%)
XOR
Exclusive or
(A% = B%) XOR (C% =
D%)
Order of Precedence
Type of Operation
symbol
Highest
Arithmetic
^
↓
Arithmetic
*, /, MOD
↓
Arithmetic
+, -
↓
Relational
=, <>, >, <, >=, <=
↓
Logical
NOT, AND, OR,
XOR
Lowest
Assignment
=
2.4Operator Precedence
The precedence of BASIC operators affects the evaluation of operands in
expressions. Expressions with higher precedence operators are evaluated
first. Precedence of BASIC operators is listed below in the order of
precedence from highest to lowest.
2.5 Labels
Line labels are used to represent some special lines in the BASIC program.
They can be either integer numbers or character strings.
A valid integer number for the line label is in the range from 1 to
65279.
A character string label can have up to 255 characters (if the string
label has more than 255 characters, error can be it cannot be
anticipated).
A character string label that precedes a program line must have a colon
between the label and the program line, but it is not necessary for an
integer label.
PT-Basic Programming Manual Ver. 1.00 11/143
For example:
GOTO 100
…
100
…
GOTO LABEL2
… LABEL2:
…
2.6 Subroutines
A subroutine is a set of instructions with a particular name or a line label.
User can simplify their programming by breaking programs into
subroutines. A subroutine will be executed when being called by a
GOSUB command.
For example:
ON COM (1) GOSUB ReadCOM
…
ReadCOM:
…
RETURN
The command RETURN marks the end of the subroutine and tells the
processor to return to the caller. A subroutine has to be appended at the
end of the main BASIC program. A subroutine can be defined with or
without a pair of brackets.
For example:
GOSUB FUN
GOSUB Place
GOSUB Test
END
…
SUB FUN( )
PRINT "Run function!!"
END SUB
PT-Basic Programming Manual Ver. 1.00 12/143
Place:
PRINT "Run Place!!"
RETURN
SUB Test
PRINT “TEST…”
END SUB
2.7 Exit program
In any place of the program, you can use “END” to exit the
program. The system will go to BASIC Menu.
PRINT "Press key to exit!"
WHILE INKEY$ = ""
WEND
END
2.8Special notes
Commands have to be appeared in uppercase letters
PRINT “OK…” → right
print “NG…” → error
Variable names are case sensitive.
ABC%、ABc%、AbC% → Three kind of different variables
ARGO%、ARGO!、ARGO$ → Three kind of different variables
PT-Basic Programming Manual Ver. 1.00 13/143
ABS
Purpose:
To return the absolute value of a numeric expression.
A% is numeric variable to be assigned to the absolute value
of a numeric expression.
N% or N! is a numeric expression, it can be an integer or a
real number.
DIM
Purpose:
To specify the maximum value of variable subscripts and to
allocate storage accordingly.
Syntax:
DIM Array (range {,range}) {, Array(range {,range})}
Example:
DIM A%(8), B%(5,5),C$(6)
Description:
Array is an array variable.
Range can be an integer or an integer expression.
3 Command Sets
3.1 General commands
PT-Basic Programming Manual Ver. 1.00 14/143
GOSUB
Purpose:
To call a specified subroutine.
Syntax:
GOSUB SubName|SubLabel|SubNumber
Example:
GOSUB FUN
GOSUB Place
GOSUB 100
END
SUB FUN( )
PRINT "Run SUBNAME"
END SUB
Place:
PRINT "Run SUBLABEL"
RETURN
100
PRINT "RunSUBNUMBER"
RETURN
Description:
SubName is the name of a subroutine.
SubLabel is the line label of a subroutine.
SubNumber is the line number of a subroutine.
GOTO
Purpose:
To branch unconditionally to a specified line number or line
lable from the normal program sequence.
Syntax:
GOTO LineNumber|LineLabel
Example:
GOTO FUN
100
PRINT "NUMBER"
WHILE INKEY$=""
WEND
END
FUN:
PRINT "LABEL NAME"
GOTO 100
Description:
LineNumber is the integer number in front of a program line.
LineLabel is the string label of a program line.
PT-Basic Programming Manual Ver. 1.00 15/143
INT
Purpose:
To return the largest integer that is less than or equal to the
giver numeric expression.
Syntax:
A% = INT(N%) or A% = INT(N!)
Example:
A% = INT(9.86)
PRINT A%
B% = INT(-5.68)
PRINT B%
Description:
A% is an integer variable to be assigned to the result.
N% or N! is a numeric expression,it can be an integer or a
real number.
REM
Purpose:
To insert explanatory remarks in a program.
Syntax:
REM remark or 'remark
Example:
REM This is function
' This is BASIC program
Description:
remark may be any sequence of characters. BASIC
interpreter will ignore whatever follows the REM or „ until
end of the line‟.
SET_PRECISION
Purpose:
To set the precision of the decimal points for printing real
number expression.
Syntax:
SET_PRECISION(N%)
Example:
A! = 3.141592654
SET_PRECISION(6)
PRINT "A = ", A! ' A = 3.141593
Description:
N% is a numeric expression in the rang of 0 to 6.
The precision default setting is two digits.
PT-Basic Programming Manual Ver. 1.00 16/143
SGN
Purpose:
To return an indication of the mathematical sign (+ or -) of a
given numeric expression.
N% or N! is a numeric expression,it can be an integer or a
real number.
A% is an integer variable to be assigned to the result.
A%
Meaning
1
N% >0
0
N% =0
-1
N% <0
PT-Basic Programming Manual Ver. 1.00 17/143
IF … THEN … {ELSE IF…} [ELSE…] END IF
Purpose:
To provide a decision structure for multiple-line conditional
execution.
Syntax:
IF condition1 THEN [statements1] {ELSE IF condition2
THEN statements2} [ELSE elsestatements] END IF
Example:
PRINT "Input a number:"
Result%=INPUT("",K%)
IF K% < 10 THEN
PRINT "One digit"
ELSE IF K% < 100 THEN
PRINT "Two digits"
ELSE
PRINT "Over one Hundry!"
END IF
Description:
condition is a logical expression.
statements can be multiple lines of BASIC statements.
3.2 Commands for decision structures
PT-Basic Programming Manual Ver. 1.00 18/143
ON … GOSUB …
Purpose:
To call one of the specified subroutines depending on the
value of the expression.
Syntax:
ON N% GOSUB SubLabel| SubName {,SubLabel|
SubName}
N% is a numeric expression that is rounded to an integer. The
value of N% determines which subroutine is to be called. If
the value of N% is 0 or greater than the number of routines
listed, the interpreter will continue with the next executable
statement.
SubLabel is the name of a subroutine.
PT-Basic Programming Manual Ver. 1.00 19/143
SubName is the line label of a subroutine.
ON … GOTO …
Purpose:
To branch to one of several specified Line Labels depending
on the value of an expression.
Syntax:
ON N% GOTO LineLabel | LineNumber {,LineLabel |
LineNumber}
Example:
D% = DAY_OF_WEEK
ON D% GOTO 1, 2, 3, 4, 5, 6, 7
1
PRINT "MONDAY"
END
2
PRINT "TUESDAY"
END
3
PRINT "WEDNESDAY"
END
4
PRINT "THURSDAY"
END
5
PRINT "FRIDAY"
END
6
PRINT "SATURDAY"
END
7
PRINT "SUNDAY"
END
Description:
N% is a numeric expression which is rounded to an
integer.The value of N% determines which line lable in the
list will be used for branching. If the value N% is 0 or greater
than the number of line labels listed,the interpreter will
continue with the next executable statement.
LineLabel is the string label of a program line.
LineNumber is the integer number in front of a program line.
PT-Basic Programming Manual Ver. 1.00 20/143
EXIT
Purpose:
To provide an alternative exit for looping structures,such as
FOR…NEXT and WHILE…WEND statements.
Syntax:
EXIT
Example:
WHILE 1
IF INKEY$=CHR$(27) THEN „if press ESC key
then quit
EXIT
END IF
WEND
PRINT "EXIT..."
Description:
EXIT can appear anywhere within the loop statement.
FOR … NEXT
Purpose:
To repeat the execution of a block of statements for a
specified number of times.
Syntax:
FOR N% = startvalue TO endvalue [STEP step]
[Statement Block]
NEXT
Example:
FOR N% = 1 TO 6 STEP 1
PRINT "FOR NEXT",N%
NEXT
Description:
N% is an integer variable to be used as loop counter.
Startvalue is a mumeric expression which is the initial value
for the loop counter.
Endvalue is a numeric expression which is the final value for
the loop counter.
Step is a numeric expression to be used as an
increment/decrement of the loop counter. The step is 1 by
default.
If the loop counter ever reaches or beyond the endvalue,the
program execution continues to the statement following the
NEXT statement. The Statement block will be executed again
otherwise.
3.3 Commands for looping structures
PT-Basic Programming Manual Ver. 1.00 21/143
WHILE … WEND
Purpose:
To repeat the execution of a block of statements while a
certain condition is TRUE.
Syntax:
WHILE condition
[Statement Block]
WEND
Example:
N%=1
WHILE 1
PRINT "Cnt=",N%
N%=N%+1
IF N%>5 THEN
EXIT
END IF
WEND
Description:
If the condition is true, loop statements are executed until the
WEND statement is encountered. Then the program
execution returns to WHILE statement and checks the
condition again. If it is still true,the process will be repeated.
Otherwise the execution continues with the statement
following the WEND statement.
A% is an integer variable to be assigned to the result.
N% is a numeric expression. Optional offset N% sets the
position for starting the search.
S1$, S2$ may be a string variable, string expression, or string
constant.
If S2$ is found in S1$, it returns the position of the first
occurrence of S2$ in S1$, from the starting point.
If N% is larger than the length of S1$ or if S1$ is null, of if
S2$ cannot be found,it return 0.
If S2$ is null,it return N%(or 1 if N% is not specified).
3.4 Commands for string processing
PT-Basic Programming Manual Ver. 1.00 23/143
LEFT$
Purpose:
To retrieve a given number of characters from the left side of
the target string.
A$ is a string variable to be assigned to the result.
Str$ may be a string variable, string expression, or string
constant.
N% and M% are numeric expression.
This command returns a string of length M% characters from
Str$ beginning with the N%th character.
If M% is equal to zero, or if N% is greater than the length of
Str$, then it returns a null string.
PT-Basic Programming Manual Ver. 1.00 24/143
RIGHT$
Purpose:
To retrieve a given number of characters from the right side
of the target string.