-*-TAGS-*- In accordance with DEC's reproduction restrictions, their copyright statement is reprinted below. Copyright c 1975 by Digital Equipment Corporation "The software described in this document is furnished to the purchaser under a license for use on a single computer system and can be copied (with inclusion of DIGITAL's copyright notice) only for use in such system, except as may otherwise be provided in writing by DIGITAL."  File: Basic, Node: Top, Up: (Dir)Programming-Systems The menu below contains the names of many BASIC topics. For info on any one of them, type the command "M" and then the first few letters of the name of the topic you want. (For example, if you want to know about resequencing BASIC programs, type in "M" followed by "RES" ). * Menu: * New User Info: (User)Top * Variable Types:: * Operators:: * Statements:: * Print Using:: * Functions: (Second)Functions * Error Messages: (Second)Error Messages * Record I/O: (Record) * Virtual Arrays: (Varray) * Sequential I/O: (Sequen) * Resequencing the Lines in a BASIC Program: (Reseq) * Cross Referencing: (Bpcref)Top  File: Basic, Node: Variable Types, Up:, prev: (user)top, next: Operators Type Variable Name Examples Floating point single letter A optionally followed by a I single digit X3 Integer any floating point variable B% name followed by a % character, D7% integers are in the range from 1 to 32767 Character String any floating point variable M$ name followed by a $ character R1$ Floating Point any floating point variable S(4%) E(5%,1%) Matrix name followed by one or two N2(8%) V8(3%,3%) dimension elements in parentheses Integer Matrix any integer variable name A%(2%) I%(3%,5%) followed by one or two dimen- E3%(4%) R2%(2%,1%) sion elements in parentheses Character String any character string variable C$(1%) S$(8%,5%) Matrix name followed by one or two A2$(8%) V1$(4%,2%) dimension elements in paren- theses Extend When operating in EXTEND mode, the variable name may consist of a letter, followed by 0 to 29 additional characters, each a letter, digit, or a dot (that is, a period/or point). The rules for specifying integers, string, and dimension elements remain the same for EXTEND mode. Note: There are some reserved words that can not be used as variable names (Examples: CHAIN, LINE END, FOR). See Appendix A.5  File: Basic, Node: Operators, Up: Top, prev: Variable Types, next: Statements Type Operator Operates Upon Arithmetic - unary minus numeric variables ^ exponentiation and constants ** exponentiation *,/ multiplication, division +,- addition, subtraction Relational = equals string or < less than numeric variables <= less than or equal to and constants > greater than >= greater than or equal to <> not equal to == approximately equal to Logical NOT logical negation relational expressions AND logical product composed of string or OR logical sum numeric elements, integer XOR logical exclusive or variables or integer IMP logical implication valued expressions EQV logical equivalence String + concatenation string constants and variables Matrix +,- addition and subtraction dimensioned vari- of matrices of equal dimen- ables. See Sec- sions, one operator per tion 6.6.1 for statement further details. * multiplication of conform- formable matrices * scalar multiplication of a matrix, see section 6.6.1  File: Basic, Node: Statements, Up: Top, Prev: Variable Types, Next: Print Using The following summary of statements available in the BASIC-PLUS language defines the general format for the statement as a line in a BASIC program. If more detailed information is needed, the reader is referred to section(s) in the manual dealing with that particular statement. In these definitions, elements in angle brackets are necessary elements of the statement. Elements in square brackets are necessary elements of which the statement may contain one. Elements in braces are optional elements of the statement. * Menu: * Comments:: * Assignment:: The LET statement * Conditionals:: If Satatements * Flow of control:: Loops * Subroutines and Functions:: * Input/output:: * Read and Data:: * Handling Errors:: * exiting a program:: * Matrix Statements:: * Statement Modifiers:: * System Statements:: * Record I/O Statements:: Where the term line number ({ln}) is shown in braces, this statement can be used in immediate mode. The various elements and their abbreviations are described below: variable or var Any legal BASIC variable. line number or ln Any legal BASIC line number. Line numbers in the range from 1 to 32767 expression or exp Any legal BASIC expresion. message Any combination of characters. condition or cond Any logical condition. constant Any acceptable integer constant (need not contain a % character). argument(s) or arg Dummy variable names. statement Any legal BASIC-PLUS statement. string Any legal string constant or variable. protection Any legal protection code. value(s) Any floating point, integer, or character string constant. list The legal list for that particular statement. dimension(s) One or two dimensions of a matrix, the maximum dimension(s) for that particular statement. RANDOMIZE ln RANDOM{IZE} 55 RANDOMIZE 70 RANDOM   File: Basic, Node: comments, Up: Statements, REM {ln} REM {ln}{}! 10 REM THIS IS A COMMENT 15 PRINT ! Perform a CR/LF  File: basic, Node: Assignment, LET {ln}{LET}{,,....} = 55 LET A%=40%: B%=22% 60 B,C,A=4.2 ! Multiple Assignment  File: Basic, Node: Conditionals, Up: Statements, [THEN ] ln IF [THEN ] [GOTO ] 55 IF A>B OR B>C THEN PRINT "NO" 60 IF FNA(R)= B THEN 250 95 IF L0 GOTO 345 IF-THEN-ELSE [THEN] ln IF [THEN] {ELSE} [GOTO] {ELSE} 30 IF B=A THEN PRINT "EQUAL" ELSE PRINT "NOT EQUAL" 50 IF A>N THEN 200 ELSE PRINT A  File: Basic, Node: Flow of control, Up: Statements, You should never need to use the GOTO statement, but we all cheat at some time or other. ln GOTO 100 GOTO 50 ON-GOTO ln ON GOTO 75 ON X GOTO 95, 150, 45, 200 FOR ln FOR = TO {} 20 FOR I%=2% TO 40% STEP 2% 55 FOR N=A TO A+R FOR-WHILE, FOR-UNTIL [WHILE] ln FOR = {STEP} [UNTIL] 84 FOR I%= 1 STEP 3 WHILE I%A OR N%=B 05 FOR B= 1 UNTIL B>10 NEXT ln NEXT 25 NEXT I% ! must match in FOR statement 60 NEXT N% 75 NEXT ! For use with the WHILE statement  File: Basic, Node: Subroutines And Functions, Up: Statements, Subroutines and functions are similar Only in that they are both TEMPORARY excursions from a point in the program you are at. At The completion of either a subroutine or a function, the next statement executed is the line after the call to the subroutine/ Function. Good programs make frequent use of functions, since subroutine calls are often difficult to read. The two chief advantages of Functions are: 1) They are named rather than just being known by line numbers. 2) They "return a value"; that is to say that their name can be used like a variable. (It is the duty of the programmer to see that a useful value is assigned to the Function Name before the FNEND statment. Subroutines: GOSUB _____ ln GOSUB 90 GOSUB 200 ! Subroutine starts on line 200 and ! ends with return statement. ON-GOSUB ln ON GOSUB 85 ON FNA(M) GOSUB 200, 250, 400, 375 RETURN ln RETURN 375 RETURN Functions: DEF, single line ln DEF FN(arg) = 20 DEF FNA(X,Y,Z)=SQR(X^2+Y^2+Z^2) DEF, multiple line ln DEF FN(arg) ln FN= ln FNEND 10 DEF FNF(M) ! Factorial Function 20 IF M=1 THEN FNF=1 ELSE FNF=M*FNF(M-1) 30 FNEND  EXTEND ln EXTEND 10 EXTEND  CHANGE [] [] {ln} CHANGE TO [] [] 25 CHANGE A$ TO X ! Converts each character of a string 70 CHANGE M TO R$ ! to its ASCII equivalent or vice versa.  Node: Input/Output PRINT {ln} PRINT{{#,}} 25 PRINT ! Generates CR/LF 75 PRINT "BEGINNING OF OUTPUT";I,A*I 45 PRINT #4,"OUTPUT TO DEVICE"FNM(A)^2;B;A PRINT USING {ln} PRINT {#,}USING , 54 PRINT USING"##.##",A 55 PRINT USING"\\###.## \\##^^^^","A=",A,"B=",B 56 B$=" ###.## #### #### " 57 PRINT USING B$,A,B,C INPUT {ln} INPUT {#,} 25 INPUT "TYPE YOUR NAME ",A$ 55 INPUT #8, A, N, B$ ! Retrieving Information from ! File #8 INPUT LINE {ln} INPUT LINE {#,} 40 INPUT LINE R$ 75 INPUT LINE #1, E$ OPEN [] {ln} OPEN {FOR }AS FILE [] {,RECORDSIZE}{,CLUSTERSIZE }{,MODE} 10 OPEN "BALANC.DAT" FOR OUTPUT AS FILE 1 20 OPEN "UPDATE.DAT" AS FILE 3 CLOSE {ln} CLOSE 100 CLOSE 2% 255 CLOSE 10, 4, N1 The symbol '&' can substitute for the word 'PRINT' in PRINT statements Examples: 500 IF T=Y THEN & "T EQUALS Y" 501 ! THIS STATEMENT IS EQUAL TO: IF T=Y THEN PRINT "T EQUALS Y" 990 & "END OF PROGRAM" 991 ! THIS STATEMENT IS EQUAL TO: PRINT "END OF PROGRAM" If the FOR loop is a single statement, then the user can substitute a single statement for this loop. Examples: 100 PRINT A(I) FOR I=1 TO 10 105 ! THIS IS THE SAME AS: 110 ! 100 FOR I=1 TO 10 115 ! 101 PRINT A(I) 120 ! 102 NEXT I 150 ! 200 B(M,N)=1 FOR N=1 TO 10 FOR M= 1 TO 15 205 ! THIS IS THE SAME AS: 210 ! 200 FOR M=1 TO 15 215 ! 201 FOR N=1 TO 10 220 ! 202 B(M,N)=1 225 ! 203 NEXT N 230 ! 204 NEXT M  Node: Read and Data, Up: Statements, READ ln READ 25 READ A, B$, C%, F1, R2, B(25%) DATA ln DATA 300 DATA 4.3, "STRING",85,49,75.04,10 RESTORE ln RESTORE ! Recycles through the DATA statements 125 RESTORE ! beginning with lowest numbered DATA statement.  Node: Handling Errors, Up: Statements, ON ERROR GOTO ln ON ERROR GOTO {} 10 ON ERROR GOTO 500 ! Enables Error Routine 525 ON ERROR GOTO ! Disables Error Routine 526 ON ERROR GOTO 0 ! Disables Error Routine RESUME ln RESUME {} 1000 RESUME ! Or RESUME 0 are equivalent 655 RESUME 200 WHILE-NEXT ln WHILE 20 WHILE LEN(A1)=0% ! End statement loop with a ! NEXT statement.  Node: Exiting a program, Up: Statements STOP ln STOP 75 STOP END ln END 999 END CHAIN ln CHAIN {} 375 CHAIN "PROG2.BAS" 500 CHAIN "MAIN.BAS" LINE 75 600 CHAIN "PROG3" A  File: Basic, Node: Matrix Statements, Up: Statements, DIM ___ ln DIM 10 DIM A(20%), B$(5%,10%), C%(45%) ln DIM #,= 75 DIM #4, A$(100%)=32,B(50%,50%) MAT READ ln MAT READ 55 DIM A(20%), B$(32%), C%(15%,10%) 90 MAT READ A, B$(25%), C% MAT PRINT {ln} MAT PRINT {#,} 10 DIM A(20%), B(15%,20%) 90 MAT PRINT A; ! Print 10*10 Matrix, Packed 95 MAT PRINT B(10%,5%), ! Print 10*5 Matrix, five ! Elements per line. 97 MAT PRINT #2, A; ! Print output into File #2 MAT INPUT {ln} MAT INPUT{#,} 10 DIM B$(40%), F1%(35%) 20 OPEN "DFILE.DAT" FOR INPUT AS FILE 3 30 MAT INPUT #3, B4, F1% MAT Initialization [{ZER}] {ln}MAT = [{CON}] {dimension(s)} [{IDN}] 10 DIM B(15%,10%), A(10%), C%(5%) 15 MAT C% = CON ! All elements of C%(I)=1 20 MAT B = IDN(10%,10%) ! Identity Matrix 10*10 95 MAT B = ZER (N%,M%) ! Clears an N by M Matrix Node: Statement Modifiers, Up: Statements, Statement Modifiers (can be used in immediate mode) IF IF 10 PRINT X IF X<>0 UNLESS UNLESS 45 PRINT A UNLESS A=0 FOR FOR = TO {STEP } 75 LET B$(I) = "PDP-11" FOR I = 1 TO 25 80 READ A(I) FOR I = 2 TO 8 STEP 2 WHILE WHILE 10 LET A(I) = FNX(I) WHILE I < 45.5 UNTIL UNTIL 115 IF B>0 THEN A(I)=B UNTIL I>5  File: Basic, Node: System statements, Up: Statements SLEEP 100 SLEEP 20 ! Dismiss job for 20 sec. WAIT 525 WAIT A%+5 ! Wait A%+5 sec. for input  File: Basic, Node: Record I/O Statements, Up: Statements LSET{,}= 90 LSET B$="XYZ" RSET{,}= 250 RSET C$="67890" FIELD#,AS{,AS} 75 FIELD#2%,10% AS A$, 20% AS B$ GET#{,RECORD} 100 GET#1%,RECORD 99% PUT#{,RECORD}{,COUNT} 500 PUT#1%,COUNT 80% UNLOCK# 700 UNLOCK #3% To place more than one logical statement on a single line, a colon or backslash can be used. Examples: 700 PRINT:PRINT:PRINT 705 ! THIS IS THE SAME AS: 710 ! 700 PRINT 715 ! 701 PRINT 720 ! 702 PRINT 725 ! 730 A$="THIS IS THE END" 735 PRINT TAB(28);\PRINT USING"\ \",A$ 740 ! THIS IS THE SAME AS: 745 ! 740 PRINT TAB(28); 750 ! 741 PRINT USING"\ \",A$ 755 ! WHICH IS ALSO THE SAME AS: 760 !740 PRINT USING" \ \",A$  File: Basic, Node: Print using, Up: top Prev: Statements, Next: (Second)Functions THE PRINT USING STATEMENT Format Control Symbols Symbol Description # One or more "pound" signs establish a numeric format. . One decimal point can be inserted anywhere within a numeric format. It specifies the location of the decimal point. ! An exclamation point indicates a one character string field. \ \ A pair of backward slashes are used to indicate the start and end of a variable string field. ** Two asterisks at the start of a numeric field indicate that any leading spaces in the format are to be filled with asterisks. $$ Two dollar signs at the start of a numeric field indicates that a single dollar sign is to be printed immediately proceding the first digit of the number. ^^^^ A numeric field followed immediately by the four upward arrows indicates that the field is to be printed in exponential form with the characters E-XX following the numeric value of the constant. - A trailing minus sign after a numeric field indicates that the sign is to be printed to the right of the output instead of preceding it. , Commas may be inserted in numeric formats to delineate the digits. Examples of the PRINT-USING statement and the use of literals in the format string: 100 A=1.32519:B=2.45457 110 F$=" A=##.## B=##.## " 120 PRINT USING F$,A,B 130 C%=-10:Z$="THE NUMBER IS" 140 G$=" \ \ ##-" 150 PRINT USING G$,Z$,C% 160 H$=" EXPONENTIAL NOTATION LOOKS LIKE THIS ####^^^^" 170 PRINT USING H$,A 180 I$=" TOTAL OF ! AND ! EQUALS ##.###" 190 PRINT USING I$,'A','B',A+B 200 D=25.25:E=0.75:E1=D+E 210 J$=" THE AMOUNT IS $$##.## " 220 PRINT USING J$,E1 230 END The output would look like this: A= 1.33 B= 2.45 THE NUMBER IS 10- EXPONENTIAL NOTATION LOOKS LIKE THIS 1325E-03 TOTAL OF A AND B EQUALS 3.780 THE AMOUNT IS $26.00  TAGS: :SGAT Top:466 Variable Types:1166 Operators:2552 Statements:3769 comments:5780 Assignment:5954 Conditionals:6111 Flow of control:6545 Subroutines And Functions:7281 Input/Output:8902 Read and Data:10617 Handling Errors:10948 Exiting a program:11390 Matrix Statements:11617 Statement Modifiers:12697 System statements:13247 Record I/O Statements:13453 Print using:14452