System/34 BASIC - BASIC Statements

BASIC Statements

These core BASIC statements, functions, and commands were used:

DATA DIM END FOR...NEXT GOSUB...RETURN GOTO IF...THEN INPUT LET ON...GOTO PRINT PRINT USING READ REM STOP ASC RND SIN COS TAN TAB SQRT LOG LIST

More advanced IBM-supplied statements included:

ON ERROR Allows error trapping OPTION Permits program-wide properties such as Base 1 or Base 0 array indexing, long or short precision, etc. OPEN Allows a file or device (formatted workstation, printer) to be opened CLOSE Closes a file or device WRITE Outputs to a file or device REWRITE Changes a record or display format APPEND Adds to a file DELETE Deletes a record from a file IMAGE Defines the format of a record using COBOL-like syntax FORM Defines the format of a record using RPG-like syntax DEF FN..FNEND Defines a function CHAIN Loads and passes control to another BASIC program PRINT #255: Prints to the (default) printer file PRINT NEWPAGE Clears the screen PRINT #255: NEWPAGE Advances to the next page on the printer file AIDX Refers to the ascending index of an array, which is an array of relative sorted pointers to array elements DIDX Same as AIDX but uses a descending index SRCH Used to find a value in an array by retrieving the match pointer SRCH$ Used to find a string value in a string array by retrieving the match pointer RENUMBER A command used to renumber the lines within a program LOAD A command used to load a program from a library on the fixed disk SAVE A command used to save a program to a library on the fixed disk OFF A command used to exit the interactive BASIC session LISTP A command used to list the current program to the printer

ON ERROR is an error-trapping statement that allows BASIC to suspend an error that might otherwise stop a BASIC program from running and perform an error-handling routine instead. Variants include suffixing OFLOW, ZDIV, and other error types to a statement and immediately trap these errors.

OPTION allows the BASIC program to meet special criteria. Sometimes BASIC did not have very much user space (since all S/34 programs are limited to 64K) and the area called "code space" which contains the current user program must reside within the user space. Therefore, users could choose OPTION LPREC which causes BASIC to compute with double-precision (long) numerics, or OPTION SPREC which provides more space and single-precision (short) numerics. Some programmers prefer matrix mathematics where the lowest-numbered index is 0, others prefer 1. OPTION BASE 0 and OPTION BASE 1 accomplish this. There are other uses for OPTION.

RPG II programs on the S/34 could not call each other, but BASIC programs could, using the CHAIN statement. CHAIN passes control from the current BASIC module to the named module, bearing a list of arguments which can become variables in the new module when it is loaded.

DEF FN allows the definition of a user function in BASIC which can be named and referred in the program. FNEND is placed after the last statement in a function.

There are four ways to format BASIC input and output. First, unformatted; just PRINT and INPUT to your heart's content. Second, with PRINT USING, which in S/34 BASIC can incorporate a constant, a string variable, a line number, or a label. Third, with PRINT FIELDS and INPUT FIELDS, which place 5250-type display fields on the CRT in immediate mode. Fourth, by using a workstation file (opened with OPEN #x: "WS,NAME=" and so forth) and performing various combinations of WRITE and READ to that workstation file, using SDA-generated screen formats similar to those in other S/34 applications. WRITE and READ, as well as PRINT USING and INPUT USING, can direct BASIC to a line number or a label that contains the keyword "IMAGE:".

An IMAGE statement contains decimals, commas, dollar signs, dashes, and pound signs ("#") in representation of the substituted numeric or alphameric values.

3540 IMAGE: ###-##-#### ############################# $#,###,###.##

A FORM statement denotes the size of the variables to be read or written. To save a numeric value of .00 to 99,999.99, use this notation:

2959 FORM N 7.2

A label is a tag on a line as follows:

260 BEGIN_CALCULATIONS:: 270 FOR X = 1 TO 12 280 Y = Y + X*1.08 290 NEXT X

If desired, the statement GOSUB BEGIN_CALCULATIONS can be used instead of GOSUB 260.

OPEN, CLOSE, WRITE, REWRITE, DELETE, and APPEND are already familiar to COBOL programmers and describe the actions taken to access S/34 disk files using BASIC. It isn't possible to access every single type of S/34 file because these include system files, libraries, and folders, but every user-created S/34 file with a fixed record length (only FORTRAN programs can use variable record lengths) will suffice. Disk files can be opened sequentially, by index, or relatively (by record number). If a file is delete-capable, records can be deleted using the DELETE statement. To add a record, use WRITE (with APPEND specified in the OPEN statement) and to update use REWRITE.

Read more about this topic:  System/34 BASIC

Famous quotes containing the words basic and/or statements:

    Not many appreciate the ultimate power and potential usefulness of basic knowledge accumulated by obscure, unseen investigators who, in a lifetime of intensive study, may never see any practical use for their findings but who go on seeking answers to the unknown without thought of financial or practical gain.
    Eugenie Clark (b. 1922)

    In so far as the statements of geometry speak about reality, they are not certain, and in so far as they are certain, they do not speak about reality.
    Albert Einstein (1879–1955)