microsoft basic 8086xenix reference
DESCRIPTION
This is the reference manual for Microsoft Quickbasic on the Xenix OS with a 8086 processorTRANSCRIPT
-
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-25
will be positionedline. Proceedsubcol1)llland.
at the first character in theby typing an edit mode
Remember, if you have just entered a line andwish to go back and edit it, the command "EDIT."will enter edit mode at the current line. (Theline number symbol "" always refers to thecurrent line.)
If an unrecognizable commandcharacter is input to Microsoftedit mode, BASIC sends a Control-Gterminal, and the command orignored.
7. Entering Edit Mode from a Syntax Error
or illegalBASIC while in
(bell) to thecharacter is
When a syntax error is encounteredexecution of a program, Microsoftautomatically enters edit mode at the linecaused the error. For example:
duringBASIC
that
)
)
10 K=2 (4)RUN?Syntax error in 1010
When you finish editing the line and press (or the E subcommand),Microsoft BASIC reinserts the line. This causesall variable values to be lost. To preserve thevariable values for examination, first exit editmode with the Q subcommand. Microsoft BASICwill return to command level, and all variablevalues will be preserved.
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2.17 END
Format END
Page 2-26
Purpose
Remarks
Example
To terminate program execution, close all files,and return to command level.
END statements may be placed anywhere in theprogram to terminate execution. Unlike the STOPstatement, END does not cause a "Break in linennnnn" message to be printed. An END statementat the end of a program is optional. MicrosoftBASIC always returns to command level after anEND is executed.
520 IF K>lOOO THEN END ELSE GOTO 20
)
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2.18 ERASE
Format ERASE
Page 2-27
)
)
Purpose
Remarks
Example
To eliminate arrays from a program.
Arrays may be redimensioned after they areERASEd, or the previously allocated array spacein memory may be used for other purposes. If anattempt is made to redimension an array withoutfirst ERASEing it, a "Redimensioned array" erroroccurs.
Microsoft BASIC Compiler does not support ERASE.
450 ERASE A,B460 DIM B(99)
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2.19 ERR AND ERL VARIABLES
Page 2-28
When an error handling routine is entered, thevariable ERR contains the error code for theerror and the variable ERL contains the linenumber of the line in which the error wasdetected. The ERR and ERL variables are usuallyused in IF... THEN statements to direct programflow in the error handling routine.
If the statement that caused the error was adirect mode statement, ERL will contain 65535.To test whether an error occurred in a directstatement, use IF 65535=ERL THEN ....Otherwise, use
IF ERR=error code THEN ..
IF ERL=line number THEN
If the line number is not on the right side_ ofthe relational operator, it cannot be renumberedwith RENUM. Because ERL and ERR are reservedvariables, neither may appear to the left of theequal sign in a LET (assignment) statement.Microsoft BASIC error codes are listed inAppendix A.
)
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2.20 ERROR
Format ERROR
Page 2-29
)
Purpose
Remarks
Example 1
To simulate the occurrence of a BASIC error, orto allow error codes to be defined by the user.
The value of must begreater than 0 and less than 255. If the valueof equals an error codealre ady in use by BASIC (see Append ix A), theERROR statement will simulate the occurrence ofthat error and the corresponding error messagewill be printed. (See Example 1.)
To define your own error code, use a value thatis greater than any used by Microsoft BASICerror codes. (It is preferable to use thehighest available values, so compatibility maybe maintained when more error codes are added toMicrosoft BASIC.) This user-defined error codemay then be conveniently handled in an errorhandling routine. (See Example 2.)
If an ERROR statement specifies a code for whichno error message has been defined, MicrosoftBASIC responds with the "Unprintable error"error message. Execution of an ERROR statementfor which there is no error handling routinecauses an error message to be printed andexecution to halt.
LIST10 S=lO20 T=530 ERROR S+T40 ENDOkRUNString too long in line 30
Or, in direct mode:
)
OkERROR 15Str ing too longOk
(You type this line.)(BASIC types th is li ne. )
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
Example 2
110 ON ERROR GOTO 400120 INPUT "WHAT IS YOUR BET";B130 IF B>5000 THEN ERROR 210
Page 2-30
400 IF ERR=210 THEN PRINT "HOUSE LIMIT IS $5000"410 IF ERL=130 THEN RESUME 120
)
)
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2.21 FIELD
Page 2-31
Format FIELD [#l, AS .
Purpose
Remarks
To allocate space for variables in a random filebuffer.
Before a GET statement or PUT statement can beexecuted, a FIELD statement must be executed toformat the random file buffer.
was OPENed.characters toFor example,
is the number under which the file is the number of
be allocated to .
)
)
Note
Example 1
FIELD 1,20 AS N$,lO AS ID$,40 AS ADD$
allocates the first 20 positions (bytes) in therandom file buffer to the string variable N$,the next 10 positions to ID$, and the next 40positions to ADD$. FIELD does NOT place anydata in the random file buffer. (See"LSET/RSET," Section 2.37, and "GET," Section2.23.)
The total number of bytes allocated in a FIELDstatement must not exceed the record length thatwas specified when the file was OPENed.Otherwise, a "Field overflow" error occurs.(The default record length is 128 bytes.)
Any number of FIELD statements may be executedfor the same file. All FIELD statements thathave been executed will remain in effect at thesame time.
Do not use a FIELDed variable name in an INPUT------ ---or LET statement. Once a variable name isFIELDed, it points to the correct place in therandom file buffer. If a subsequent INPUT orLET statement with that variable name isexecuted, the variable's pointer is moved tostr ing space.
FIELD 1,20 AS N$,lO AS ID$,40 AS ADD$
Allocates the first 20 positions (bytes) in therandom file buffer to the string variable N$,the next 10 positions to ID$, and the next 40positions to ADD$. FIELD does NOT place anydata in the random file buffer. (See also"GET," Section 2.23, and "LSET/RSET," Section2.37.)
-
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-32
Example 2
Example 3
10 OPEN "R,"ll,"A:PHONELST",3515 FIELD 11,2 AS RECNBR$,33 AS DUMMY$20 FIELD 11,25 AS NAMES,lO AS PHONENBR$25 GET U30 TOTAL=CVI(RECNBR)$35 FOR I=2 TO TOTAL40 GET U, I45 PRINT NAMES, PHONENBR$50 NEXT I
Illustrates a multiple defined FIELD statement.In statement 15, the 35 byte field is definedfor the first record to keep track of the numberof records in the file. In the next loop ofstatements (35-50), statement 20 defines thefield for individual names and phone numbers.
10 FOR LOOP%=O TO 720 FIELD 11, (LOOP%*16) AS OFFSETS,16 ASA$ (LOOP%)30 NEXT LOOP%
Shows theusing anresult is
construction of a FIELD statementarray of elements of equal size. The
equivalent to the single declaration:
Example 4
FIELD 11,16 AS A$(0),16 AS A$(1), .. ,16 ASA$(6),16 AS A$(7)
10 DIM SIZE% (NUMB%): REM ARRAY OF FIELD SIZES20 FOR LOOP%=O TO NUMB%:READ SIZE%(LOOP%): NEXT LOOP%30 DATA 9,10,12,21,41
120 DIM A$(NUMB%): REM ARRAY OF FIELDEDVARIABLES130 OFFSET%=O140 FOR LOOP%=O TO NUMB%150 FIELD 11,OFFSET% AS OFFSET$,SIZE%(LOOP%)AS A$ (LOOP%)1600FFSET%=OFFSET%+SIZE%(LOOP%)170 NEXT LOOP%
)
Creates aHowever,elemen t.
field in the same manner as Example 3.the element size varies with eachThe equivalent declaration is:
FIELD Il,SIZE%(O) AS A$(O),SIZE%(l) AS A$(l), ..SIZE%(NUMB%) AS A$(NUMB%)
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2.22 FOR... NEXT
Format FOR =x TO y [STEP z]
NEXT [] [, .. ]
Page 2-33
)
Purpose
Remarks
where x, y, and z are numeric expressions.
To allow a series of instructions to beperformed in a loop a given number of times.
is used as a counter. The firstnumeric expression (x) is the initial value ofthe counter. The second numeric expression (y)is the final value of the counter. The programlines following the FOR statement are executeduntil the NEXT statement is encountered. Thenthe counter is adjusted by the amount specifiedby STEP. A check is performed to see if thevalue of the counter is now greater than thefinal value (y). If it is not greater,Microsoft BASIC branches back to the statementafter the FOR statement and the process isrepeated. If it is greater, execution continueswith the statement following the NEXT statement.This is a FOR .. NEXT loop.
If STEP is not specified, the increment isassumed to be one. If STEP is negative, thefinal value of the counter is set to be lessthan the initial value.. The counter isdecreased each time through the loop. The loopis executed until the counter is less than thefinal value.
The counter must be an integer orprecision numeric constant. If aprecision numeric constant is used, amismatch" error will result.
singledouble
"Type
The body of the loop is skipped if thevalue of the loop times the sign ofexceeds the final value times the signSTEP.
Nested Looos
initialthe STEPof the
)
FOR NEXT loops may be nested; that is, aFOR...NEXT loop may be placed within the contextof another FOR... NEXT loop. When loops arenested, each loop must have a unique variablename as its counter. The NEXT statement for the
-
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-34
inside loop must appear before that foroutside loop. If nested loops have the samepoint, a single NEXT statement may be usedall of them.
theendfor
Example 1
Example 2
The variable(s) in the NEXT statement may beomitted, in which case the NEXT statement willmatch the most recent FOR statement. If a NEXTstatement is encountered before itscorresponding FOR statement, a "NEXT withoutFOR" error message is issued and execution isterminated.
10 K=lO20 FOR I=l TO K STEP 230 PRINT I;40 K=K+IO50 PRINT K60 NEXTRUN
1 203 305 407 509 60
Ok
10 J=O20 FOR I=l TO J30 PRINT I40 NEXT I
)
In this example, thebecause the initialthe final value.
loop does not executevalue of the loop exceeds
Example 3 10 I=520 FOR I=l TO I+530 PRINT I;40 NEXTRUN
1 2 3 4 5 6 7 8 9 10Ok
In this example, the loop executes ten times.The final value for the loop variable is alwaysset before the initial value is set.
Note Previous versions of Microsoftinitial value of the loopsetting the final value; i. e.,would have executed six times.
BASIC set thevariable beforethe above loop
)
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2.23 GET
Format GET [#][,]
Page 2-35
)
)
Purpose
Remarks
Example
Note
To read a record from a random disk file into arandom buffer.
is the number under which the filewas OPENed. If is omitted, thenext record (after the last GET) is read intothe buffer. The largest possible record numberis 32767.
See "Microsoft BASIC Dis k I/O," in the MicrosoftBASIC User's Guide.
After a GET statement has been executed, INPUT#and LINE INPUT# may be executed to readcharacters from the random file buffer.
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2.24 GOSUB .. RETURN
Format GOSUB
RETURN
Page 2-36
Purpose To branch to and return from a subroutine.
Remarks is the firstsubroutine.
line of the
Example
A subroutine may be called any number of timesin a program. A subroutine also may be calledfrom within another subroutine. Such nesting ofsubroutines is limited only by available memory.
The RETURN statement(s) in a subroutine causeMicrosoft BASIC to branch back to the statementfollowing the most recent GOSUB statement. Asubroutine may contain more than one RETURNstatement, should logic dictate a return atdifferent points in the subroutine. Subroutinesmay appear anywhere in the program, but it isrecommended that the subroutine be readilydistinguishable from the main program. Toprevent inadvertent entry into the subroutine,precede it with a STOP, END, or GOTO statementthat directs program control around thesubroutine.
10 GOSUB 4020 PRINT "BACK FROM SUBROUTINE"30 END40 PRINT "SUBROUTINE";50 PRINT " IN";60 PRINT" PROGRESS"70 RETURNRUNSUBROUTINE IN PROGRESSBACK FROM SUBROUTINEOk
)
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2.25 GOTO
Format GOTO
Page 2-37
Purpose
Remarks
To branch unconditionally out of the normalprogram sequence to a specified line number.
If is an executable statement,that statement and those following are executed.If it is a nonexecutable statement, executionproceeds at the first executable statementencountered after .
)
)
Example LIST10 READ R20 PRINT "R =" iR,30 A=3.14*R A 240 PRINT "AREA =" ;A50 GOTO 1060 DATA 5,7,12OkRUNR = 5 AREA = 78.5R = 7 AREA = 153.86R = 12 AREA = 452.16?Out of data in 10Ok
-
MIC~OSOFT BASIC COMMANDS AND STATEMENTS Page 2-38
Format
Format
Purpose
Remarks
IF THEN {
-
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-39
)
)
Note
Example 1
Example 2
Example 3
When using IF to test equality for a value thatis the result of a floating-point computation,remember that the internal representation of thevalue may not be exact. Therefore, the testshould be against the range over which theaccuracy of the value may vary. For example, totest a computed variable A against the value1.0, use:
IF ABS (A-l.0)
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2.27 INPUT
Page 2-40
Format
Purpose
Remarks
INPUT[;] [:]
To allow input from the terminal during programexecution.
When an INPUT statement is encountered, programexecution pauses and a question mark is printedto indicate the program is waiting for data. If is included, the string isprinted before the question mark. The requireddata is then entered at the terminal.
A comma may be used instead of a semicolon afterthe prompt string to suppress the question mark.For example, the statement INPUT "ENTERBIRTHDATE" ,B$ will print the prompt with noquestion mark.
If INPUT is immediately followed by a semico~on,then the carriage return typed by the user toinput data does not echo a carriage return/linefeed sequence.
The data that is entered is assigned tovariable(s) given in .number of data items supplied must be theas the number of variables in the list.items are separated by commas.
theThe
sameData
)
The variable names in the list may be numeric orstring variable names (including subscriptedvariables). The type of each data item that isinput must agree with the type specified by thevariable name. (Strings input to an INPUTstatement need not be surrounded by quotationmarks. )
Responding to INPUT with too many or too fewitems or with the wrong type of value (numericinstead of string, etc.) causes the messsage"?Redo from start" to be printed. No assignmentof input values is made until an acceptableresponse is given.
)
-
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-41
by the userquestion mark.)
xX "SQUARED IS" XA 2
10 INPUT20 PRINT30 ENDRUN? 5 (The 5 was typed in
in response to the5 SQUARED 'Is 25
Ok
Examples
LIST ,10 PI=3.1420 INPUT "WHAT IS THE RADIUS"; R30 A=PI*R A 240 PRINT "THE AREA OF THE CIRCLE IS";A50 PRINT60 GOTO 20OkRUNWHAT IS THE RADIUS? 7.4 (User types 7.4)THE AREA OF THE CIRCLE IS 171.946
WHAT IS THE RADIUS?etc.
)
)
-
MICROSOFT BASIC COMMANDS AND STATlliENTS
2.28 INPUTji
Format INPUTji,
Page 2-42
Purpose
Remarks
Example
To read data items from a sequential disk fileand assign them to program variables.
is the number used when the filewas OPENed for input. containsthe variable names that will be assigned to theitems in the file. (The variable type mustmatch the type specified by the variable name.)with INPUTji, no question mark is printed, aswith INPUT.
The data items in the file should appear just asthey would if data were being typed in responseto an INPUT statement. With numeric values,leading spaces, carriage returns, and line feedsare ignored. The first character encounteredthat is not a space, carriage return, or linefeed is assumed to be the start of a number.The number terminates on a space, carriagereturn, line feed, or comma.
If Microsoft BASIC is scanning the sequentialdata file for a string item, leading spaces,carriage returns, and line feeds are alsoignored. The first character encountered thatis not a space, carriage return, or line feed isassumed to be the start of a string item. Ifthis first character is a quotation mark ("),the string item will consist of all charactersread between the first quotation mark and thesecond. Thus, a quoted string may not contain aquotation ma"rk as a character. If the firstcharacter of the string is not a quotation mark,the string is an unquoted string, and willterminate on a comma, carriage return, or linefeed (or after 255 characters have been read).If end-of-file is reached when a numeric orstring item is being INPUT, the item isterminated.
See "Microsoft BASIC Disk I/O," in the MicrosoftBASIC User's Guide.
)
)
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2.29 KILL
Format KILL
Page 2-43
Purpose To delete a file from disk.
Remarks If a KILLcurrentlyoccurs.
statement is given for a file that isOPEN, a "File already open" error
KILL is usedprogram files,data files.
for all types of disk files:random data files, and sequential
)
)
Example 200 KILL "DATA1.DAT"
See also "Microsoft BASIC Dis k I/O," in theMicrosoft BASIC User's Guide.
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2.30 LET
Format [LET ]=
Page 2-44
Purpose To assign the value of an expression to avariable.
Remarks
Example
Notice the word LET is optional; Le.,equal sign is sufficient for assigningexpression to a variable name.
110 LET D=12120 LET E=lY2130 LET F=12 A 4140 LET SUM=D+E+F
or
110 D=12120 E=12~2130 F=12 A 4140 SUM=D+E+F
thean
)
)
-
MICROSOFT BASIC COMMANDS A..'
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2.32 LINE INPUT#
Page 2-46
Format LINE INPUT#,
Purpose To readwithoutfile to
an entire line (up to 254 characters),delimiters, from a sequential disk data
a string variable.
Remarks is the number under which the filewas OPENed. is the variablename to which the line will be assigned. LINEINPUT# reads all characters in the sequentialfile up to a carriage return. It then skipsover the carriage return/line feed sequence.The next LINE INPUT# reads all characters UP tothe next carriage return. (If a - linefeed/carriage return sequence is encountered, itis pre se rved. )
LINE INPUT# is especially useful if each line ofa data file has been broken into fields, or if aMicrosoft BASIC program saved in ASCII format isbeing read as data by another program. (See"SAVE," Section 2.60.)
Example 10 OPEN "O",l,"LIST"20 LINE INPUT "CUSTOMER INFORMATION? ";C$30 PRINT U, C$40 CLOSE 150 OPEN "I",l,"LIST"60 LINE INPUT #1, C$70 PRINT C$80 CLOSE 1RUNCUSTOMER INFORMATION? LINDA JONES 234,4LINDA JONES 234,4 MEMPHISOk
MEMPHIS
)
)
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2.33 LIST
Page 2-47
)
Format 1
Format 2
Purpose
Remarks
LIST[
-
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-48
Examples Format 1
LIST
LIST 500
Format 2
Lists the program currentlyin memory.
Lists line 500.
LIST 150- Lists all lines from 150to the end.
LIST -1000 Lists all lines from thelowest number through 1000.
LIST 150-1000 Lists lines 150 through1000, inclusive.
)
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2.34 LLIST
Page 2-49
Format LLIST [ [-[]]]
Purpose
Remarks
To list all or part of the program currently inmemory at the line printer.
LLIST assumes a 132-character-wi~e printer.
Microsoftafter anLLIST are
BASIC always returns to command levelLLIST is executed. The options for
the same as for LIST, Format 2.
)
)
Note
Example
LLIST and LPRINT are not included inimplementations of Microsoft BASIC.
See the examples for "LIST," Format 2.
all
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2.35 LOAD
Format LOAD [,R]
Page 2-50
Purpose
Remarks
Example
To load a file from disk into memory.
is the name that was used when thefile was SAVEd. (Your operating system mayappend a default filename extension if one wasnot supplied in the SAVE command. Refer to"Microsoft BASIC Disk I/O," in the MicrosoftBASIC User's Guide, for information aboutpossible filename extensions your operatingsystem. )
The R option automatically runs the programafter it has been loaded.
LOAD closes all open files and deletes allvariables and program lines currently residingin memory before it loads the designatedprogram. However, if the R option is used withLOAD, the program is RUN after it is LOADed, andall open data files are kept open. Thus, LOADwith the R option may be used to chain severalprograms (or segments of the same program).Information may be passed between the programsusing their disk data files.
LOAD "STRTRK", R
LOAD "B:MYPROG"
)
-
MICROSOFT BASIC COM..~ANDS AND STATEMENTS
2.36 LPRINT AND LPRINT USING
Format LPRINT []
Page 2-51
Purpose
LPRINT USING ;
To print data at the line printer.
Remarks Same as PRINT andgoes to the lineSection 2.50.
PRINT USING, except outputprinter. See Section 2.49 and
)
)
Note
LPRINT assumes a 132-character-wide printer.
LPRINT and LLIST are not included inimplementations of Microsoft BASIC.
all
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2.37 LSET AND RSET
Page 2-52
Format LSET =RSET =
Purpose
Remarks
Examples
To move data from memory to a random file buffer(in preparation for a PUT statement) .
If requires fewer bytes thanwere FIELDed to , LSETleft-justifies the string in the field, and RSETright-justifies the string. (Spaces are used topad the extra positions.) If the string is toolong for the field, characters are dropped fromthe right. Numeric values must be converted tostrings before they are LSET or RSET. See"MKI$, MKS$, MKD$," Section 3.26.
150 LSET A$=MKS$(AMT)160 LSET D$=DESC($)
See also "Microsoft BASIC Disk I/O,"in the Microsoft BASIC User's Guide.
Note LSET or RSET may also be used withstring variable to left-justify ora string in a given field. Forprogram lines
110 A$=SPACE$(20)120 RSET A$=N$
a nonfieldedr ight-j ustifyexample, the )
right-justify the string N$ in a 20-characterfield. This can be very handy for formattingprinted output.
)
-
MICROSOFT BASIC CO~~ANDS AND STATEMENTS
2.38 MERGE
Format MERGE
Page 2-53
)
)
Purpose
Remarks
Example
To merge a specified disk file into the programcurrently in memory.
is the name used when the file wasSAVEd. (Your operating system may append adefault filename extension if one was notsupplied in the SAVE command. Refer to"Microsoft BASIC Disk I/O," in the MicrosoftBASIC User's Guide, for information aboutpossible filename extensions under youroperating system.) The file must have been SAVEdin ASCII format. (If not, a "Bad file mode"error occurs.)
If any lines in the disk file have the same linenumbers as lines in the program in memory, thelines from the file on disk will replace thecorresponding lines in memory. (MERGEing may bethought of as "inserting" the program lines ondisk into the program in memory.)
Microsoft BASIC always returns to command levelafter executing a MERGE command.
MERGE "NUMBRS"
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2.39 MID$
Format MID$string expl>,n[,m])=
Page 2-54
where nandexpressions.
m are integer expressions andand are string
Purpose
Remarks
Example
To replace a portion of one string with anotherstring.
The characters in , beginning atposition n, are replaced by the characters in. The optional "m" refers to thenumber of characters from thatwill be used in the replacement. If "m" isomitted, all of is used. However,regardless of whether "m" is omitted orincluded, the replacement of characters nevergoes beyond the original length of .
10 A$="KANSAS CITY, MO"20 MID$(A$,14)="KS"30 PRINT A$RUNKANSAS CITY, KS
MID$ is also a function that returns a substringof a given string. See Section 3.25.
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2.40 NAME
Format NAME AS
Page 2-55
)
)
Purpose
Remarks
Example
To change the name of a disk file.
must exist and must not exist; otherwise, an error willresult. After a NAME command, the file existson the same disk, in the same area of diskspace, with the new name.
OkNAME "ACCTS" AS "LEDGER"Ok
In this example, the file that wasformerly named ACCTS will now be named LEDGER.
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2.41 NE'il
Format NEW
Page 2-56
Purpose To delete the program currently in memory andclear all variables.
Remarks NEW is entered at command levelbefore entering a new program.always returns to command levelexecuted.
to clear memoryMicrosoft BASIC
after a NEW is
Example NEW
)
)
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2.42 NULL
Format NULL
Page 2-57
)
).
Purpose
Remarks
Example
To set the number of nulls to be printed at theend of each line.
For 10 character-per-second tape punches, should be >=3. When tapesare not being punched, should be 0 or 1 for Teletype(R) andTeletype-compatible terminal screens. should be 2 or 3 for 30 CPS hardcopy printers. The default value is o.
OkNULL 2Ok100 INPUT X200 IF X
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2.43 ON ERROR GOTO
Format ON ERROR GOTO
Page 2-58
Purpose
Remarks
Note
Example
To enable error handling and specify the firstline of the error handling routine.
Once error handling has been enabled, all errorsdetected, including direct mode errors (e.g.,syntax errors), will cause a jump to thespecified error handling routine. If does not exist, an "Undefined line"error results.
To disable error handling, execute an ON ERRORGOTO O. Subsequent errors will print an errormessage and halt execution. An ON ERROR GOTO 0statement that appears in an error handlingroutine causes Microsoft BASIC to stop and printthe error message for the error that caused thetrap. It is recommended that all error handlingroutines execute an ON ERROR GOTO 0 if an erroris encountered for which there is no recoveryaction.
If an error occurs during execution of an errorhandling routine, that error message is printedand execution terminates. Error trapping doesnot occur within the error handling routine.
10 ON ERROR GOTO 1000
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2.44 ON . GOSUB AND ON .. GOTO
Page 2-59
Format ON GOTO
ON GOSUB
specified linereturned when an
Purpose
Remarks
To branch to one of severalnumbers, depending on the valueexpression is evaluated.
The value of determinesnumber in the list will be used forFor example, if the value is three,line number in the list will be theof the branch. (If the value is athe fractional portion is rounded.)
which linebranching.the third
destinationnoninteger,
)
)
Example
In the ON ... GOSUB statement, each line number inthe list must be' the first line number of asubroutine.
If the value of is zero or greaterthan the number of items in the list (but lessthan or equal to 255), Microsoft BASIC continueswith the next executable statement. If thevalue of is negative or greaterthan 255, an "Illegal function call" erroroccur s.
100 ON L-l GOTO 150,300,320,390
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2.45 OPEN
Page 2-60
Format OPEN ,[i],[,]
Purpose
Remarks
To allow I/O to a disk file.
A disk file must be OPENed before any diskoperation can be performed on that file.allocates a buffer for I/O to the filedetermines the mode of access that will bewi th the buffe r.
I/OOPEN
andused
is a string expression whosecharacter is one of the following:
o Specifies sequential output mode.
I Specifies sequential.input mode.
fir st
R Specifies random input/output mode.
is an integer expression whosevalue is between 1 and 15. The number is thenassociated with the file for as long as it isOPEN and is used to refer other disk I/Ostatements to the file.
is a string expression containing aname that conforms to your operating system'srules for disk filenames.
)
is an integer expressionincluded, sets the record lengthfiles. The default record length is
which, iffor random
128 bytes.
Note
Example
A file can be OPENed for sequential input orrandom access on more than one file number at atime. A file may be OPENed for output, however,on only one file number at a time.
10 OPEN "I" ,2 ,"INVEN"
See also "Microsoft BASIC Disk I/O," in theMicrosoft BASIC User's Guide.
)
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2.46 OPTION BASE
Format OPTION BASE n
where n is 1 or 0
Page 2-61
Purpose To declare thesubscripts.
minimum value for array
)
)
Remarks
Example
The default base is O. If the statement
OPTION BASE 1
is executed, the lowest value an array subscriptmay have is 1.
OPTION BASE 1
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2.47 OUT
Format OUT I,J
Page 2-62
Purpose
where I and J are integer expressions in therange a to 255.
To send a byte to a machine output port.
Remarks
Example
The integer expression IThe integer expressiontransmitted.
100 OUT 32,100
is the per t number.J is the data to be
)
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2.48 POKE
Format POKE I,J
where I and J are integer expressions.
Page 2-63
Purpose
Remarks
To write a byte into a memory location.
I and J-are integer expressions. The expressionI represents the address of the memory locationand J is the data byte. I must be in the range-32768 to 65535. (For interpretation ofnegative values of I, see "VARPTR," Section3.43 )
The complementary function to POKE is PEEK.argument to PEEK is an address from which ais to be read. See Section 3.28.
Thebyte
)
)
Example
POKE and PEEK are useful for storing dataefficiently, loading assembly languagesubroutines, and passing arguments and resultsto and from assembly language subroutines.
10 POKE &H5AOO,&HFF
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2.49 PRINT
Format PRINT []
Page 2-64
Purpose
Remarks
To output data at the terminal.
If is omitted, a blankline is printed. If isincluded, the values of the expressions areprinted at the terminal. The expressions in thelist may be numeric and/or string expressions.(Strings must be enclosed in quotation marks.)
Print Positions
The position of each printed item is determinedby the punctuation used to separate the items inthe list. Microsoft BASIC divides the line intoprint zones of 14 spaces each. In the list ofexpressions, a comma causes the next value to beprinted at the beginning of the next zone. Asemicolon causes the next value to be printedimmediately after the last value. Typing one ormore spaces between expressions has the sameeffect as typing a semicolon.
If a comma or a semicolon terminates the list ofexpressions, the next PRINT statement beginsprinting on the same line, spacing accordingly.If the list of expressions terminates without acomma or a semicolon- a carriage return isprinted at the end of the line. If the printedline is longer than the terminal width,Microsoft BASIC goes to the next physical lineand continues printing.
Printed numbers are always followed by a space.Positive numbers are preceded by a space.Negative numbers are preceded by a minus sign.Single precision numbers that can be representedwith 6 or fewer digits in the unsealed format noless accurately than they can be represented inthe scaled format, are output using the unsealedformat. For example, lE-7 is output as .0000001and lE-S(-7) is output as IE-OS. Doubleprecision numbers that can be represented with16 or fewer digits in the unsealed format noless accurately than they can be represented inthe scaled format, are output using the unsealedformat. For example, lD-15 i~ output as.0000000000000001 and ID-16 is output as lD-16.
A question mark may be used in place of the wordPRINT in a PRINT statement.
)
)
-
MICROSOFT BASIC COMHANDS AND STATEMENTS Page 2-65
)Example 1 10 X=5
20 PRINT X+5,X-5,X*(-5),X A 530 ENDRUN
10 0 -25Ok
3125
In thisstatementbeginning
example, the commas in thecause each value to be printed
of the next print zone.
PRINTat the
)
Example 2 LIST10 INPUT X20 PRINT X "SQUARED IS" X A 2 "AND";30 PRINT X "CUBED IS" XA 340 PRINT50 GOTO 10OkRUN? 9
9 SQUARED IS 81 AND 9 CUBED IS 729
? 2121 SQUARED IS 441 AND 21 CUBED IS 9261
?
In this example, the semicolon at the end ofline 20 causes both PRINT statements to beprinted on the same line. Line 40 causes ablank line to be printed before the next prompt .
Example 3 10 FOR X=l TO 5
20 J=J+530 K=K+IO40 ?JiKi50 NEXT XOkRUN
5 10 10 20 15 30 20 40 25 50Ok
In this example, the semicolons in the PRINTsta temen t cause each value to be pr in tedimmediately after the preceding value. (Don'tforget, a number is always followed by a space,and positive numbers are preceded by a space.)In line 40, a question mark is used instead ofthe word PRINT.
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2.50 PRINT USING
Page 2-66
Format PRINT USING ;
Purpose
RemarksandExamples
To print strings or numbers using a specifiedformat.
is comprised of the stringexpressions or numeric expressions that are tobe printed, separated by semicolons. is a string literal (or variable) composedof special formatting characters. Theseformatting characters (see below) determine thefield and the format of the printed strings ornumbers.
String Fields
When PRINTof threeformat the
USING is used to printformatting charactersstring field:
strings, onemay be used to
"!" Specifies that only the first character in thegiven string is to be printed.
"\n spaces\"Specifies that 2+n characters from the stringare to be printed. If the backslashes are typedwith no spaces, two characters will be printed;with one space, three characters will beprinted, and so on. If the string is longerthan the field, the extra characters areignored. If the field is longer than thestring, the string will be left-justified. in thefield and padded with spaces on the right.
Example:
10 A$="LOOK" :B$="OOT"30 PRINT USING "!"; A$; B$40 PRINT USING "\ \" ;A$;B$50 PRINT USING "\ \";A$;B$;"!!"RUNLOLOOKOUTLOOK OUT !!
)
-
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-67
"&" Specifies a variable length string field. Whenthe field is specified with "&", the string isoutput without modification.
Example:
10 A$="LOOK" :B$="OOT"20 PRINT USING "!"; A$;30 PRINT USING "&" ;B$RUNLOUT
Numeric Fields
When PRINTfollowingformat the
USING is used to print numbers, thespecial characters may be used tonumeric field:
)
)
+
A number sign is used to represent each digitposition. Digit positions are always filled.If the number to be printed has fewer digitsthan positions specified, the number will beright-justified (preceded by spaces) in thefield.
A decimal point may be inserted at any positionin the field. If the fermat string specifiesthat a digit is to precede the decimal point,the digit will always be printed (as 0, ifnecessary). Numbers are rounded as necessary.
PRINT USING "iHi. iH!" ; .780.78
PRINT USING "##LH";987.654987.65
PRINT USING "iHi.## ";10.2,5.3,66.789,.23410.20 5.30 66.79 0.23
In the last example, three spaces were insertedat the end of the format string to separate theprinted values on the line.
A plus sign at the beginning or end of theformat string will cause the sign of the number(plus or minus) to be printed before or afterthe number.
-
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-68
A minus sign at the end of the format field willcause negative numbers to be printed with atrailing minus sign.
PRlllT USING "+H.## ",-68.95,2.4,55.6,-.9-68.95 +2.40 +55.60 -0.90
PRlllT USING "##.##- ",-68.95,22.449,-7.0168.95- 22.45 7.01-
** A double asterisk at thestring causes leadingfield to be filled withspecifies positions for
beginning of the formatspaces in the numeric
asterisks. The ** alsotwo more digits.
PRlllT USING "**#.# ",12.39,-0.9,765.1*12.4 *-0.9 765.1
$$ A double dollar sign causes a dollar sign to beprinted to the immediate left of the formattednumber. The $$ specifies two more digitpositions, one of which is the dollar sign. Theexponential format cannot be used with $$.Negative numbers cannot be used unless the minussign trails to the right.
PRlllT USING "$$###.##",456.78$456.78
**$ The **$ at the beginning of a format stringcombines the effects of the above two symbols.Leading spaces will be asterisk-filled and adollar sign will be printed before the number.**$ specifies three more digit positions, one ofwhich is the dollar sign.
PRlllT USING "**$H.##",2.34***$2.34
A comma that is to the left of the decimal pointin a formatting string causes a comma to beprinted to the left of every third digit to theleft of the decimal point. A comma that is atthe end of the format string is printed as partof the string. A comma specifies another digitposition. The comma has no effect if used withthe exponential ( ) format.
PRlllT USING "H##,.1I#",1234.51,234.50
PRlllT USING "##H.##,",1234.51234.50, )
-
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-69
Four carets (or up-arrows) may be placed afterthe digit position characters to specifyexponential format. The four carets allow spacefor E+xx to be pr in ted. Any dec imal poin tposition may be specified. The significantdigits are left-justified, and the exponent isadjusted. Unless a leading + or trailing + or -is specified, one digit position will be used tothe left of the decimal point to print a spaceor a minus sign.
PRrnT USING "U.H AAAA ";234.562.35E+02
PRrnT USING ".*H*AAAA_";888888.8889E+06
PRrnT USING "+.**AAAA,, ;123+.12E+03
An underscore innext charactercharacter.
the format stringto be output as
causes thea literal
PRrnT USING" !##.IHI !";12.34!12.341
) The literal characterunderscore by placing "
itself may be an" in the format string.
% If the number to bespecified numericprinted in front ofcauses the number tosign will be printednumber.
printed is larger than thefield, a percent sign isthe number. If roundingexceed the field, a percentin front of the rounded
)
PRrnT USING "## .##" ;111.22%111. 22
PRrnT USING ".##";.999%1. 00
If the number of digits specified exceeds 24, an"Illegal function call" error will result.
-
MICROSOFT BASIC COMM&~DS AND STATEMENTS
2.51 PRINT# AND PRINT# USING
Page 2-70
Format
Purpose
Remarks
PRINT#, [USING ;l
To write data to a sequential disk file.
is the number used when the filewas OPENed for output. consists offormatting characters as described in Section2.50, "PRINT USING." The expressions in are the numeric and/or stringexpressions that will be written to the file.
PRINT# does not compress data on the disk. Animage of the data is written to the disk, justas it would be displayed on the terminal screenwith a PRINT statement. For this reason, care,should be taken to delimit the data on the disk,so that it will be input correctly from thedisk.
In the list of expressions, numericshould be delimited by semicolons.
PRINT#l,A;B;C;X;Y;Z
expre ss ionsFor example:
(If commas are used as delimiters, theblanks that are inserted between printwill also be written to the disk.)
extrafields
String expressions must be separated bysemicolons in the list. To format the stringexpressions correctly on the disk, use explicitdelimiters in the list of expressions.
For example, let A$="CAMERA" and B$="93604-1".The statement
PRINT#l ,A$; B$
would write CAMERA93604-1 to the disk. Becausethere are no delimiters, this could not be inputas two separate strings. To correct theproblem, insert explicit delimiters into thePRINT# statement as follows:
PRINT#l,A$;",";B$
The image written to disk is
CAMERA,93604-1
which can be read back into two string)
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
variables.
Page 2-71
If the strings themselves containsemicolons, significant leading blanks,returns, or line feeds, write themsurrounded by explicit quotationCHR$ (34)
commas,carriageto disk
marks,
ForB$="
example, let A$="CAMERA, AUTOMATIC"93604-1". The statement
and
PRINTU ,A$; B$
would write the following image to disk:
CAMERA, AUTOMATIC
And the statement
INPUTU ,A$,B$
93604-1
PRINT#l,CHR$ (34) ;A$;CHR$ (34) ;CHR$(34) ;B$ ;CHR$ (34))
would input "CAMERA" to"AUTOMATIC 93604-1" to B$. Tostrings properly on the disk,quotation marks to the diskCHR$(34). The statement
A$ . andsepara te these
wr i te doubleimage using
writes the following image to disk:
"CAMERA, AUTOMATIC""
And the statement
INPUTU ,A$,B$
93604-1 "
would input "CAMERA, AUTOMATIC" to" 93604-1" to B$.
A$ and
)
The PRINT# statement may also be used with theUSING option to control the format of the diskfile. For example:
PRINT#l,USING"$$###.##,";J;K;L
For more examples using PRINT#, see "MicrosoftBASIC Disk I/O," in the Microsoft BASIC User'sGuide.
See also "WRITE.," Section 2.68.
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2.52 PUT
Format PUT [*][,]
Page 2-72
Purpose
Remarks
Example
Note
To write a record from a random buffer to arandom disk file.
is the number under which the filewas OPENed. If is omitted, therecord will assume the next available recordnumber (after the last PUT). The largestpossible record number is 32,767. The smallestrecord number is 1.
See "Microsoft BASIC Disk I/O," in the MicrosoftBASIC User's Guide.
PRINT*, PRINT* USING, and WRITE# may be used toput characters in the random file buffer beforeexecuting a PUT statement.
In the case of WRITE#, Microsoft BASIC pads thebuffer with spaces up to the carriage return.Any attempt to read or write past the end of thebuffer causes a "Field overflow" error.
)
)
-
MICROSOFT BASIC COMMANDS AND STATDIENTS Page 2-73
2.53 RANDOMIZE
Format RANDOMIZE [ ]
Purpose To reseed the random number generator.
Remarks If suspends programby printing
is omitted, Microsoft BASICexecution and asks for a value
Random Number Seed (-32768 to 32767)?
before executing RANDOMIZE.
If the random number generator is not reseeded,the RND function returns the same sequence ofrandom numbers each time the program is RUN. Tochange the sequence of random numbers every timethe program is RUN, place a RANDOMIZE statementat the beginning of the program and change theargument with each RUN.
to 32767)? 4sequence)
.292443 .322921
(-32768for new.929364
10 RANDOM I ZE20 FOR I=l TO 530 PRINT RND;40 NEXT IRUNRandom Number Seed (-32768 to 32767)? 3
(user types 3).88598 .484668 .586328 .119426 .709225
OkRUNRandom Number Seed
(user types 4.803506 .162462
OkRUNRandom Number Seed (-32768 to 32767)? 3
(same sequence as first RUN).88598 .484668 .586328 .119426 .709225
Ok
Example
)
)
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2.54 READ
Format READ
Page 2-74
Purpose
Remarks
Example 1
To read values from a DATA statement and assignthem to var iables. (See "DATA," Section 2.10.)
A READ statement must always be used inconjunction with a DATA statement. READstatements assign variables to DATA statementvalues on a one-to-one basis. READ statementvariables may be numeric or string, and thevalues read must agree with the variable typesspecified. If they do not agree, a "Syntaxerror" will result.
A single READ statement may access one or moreDATA statements (they will be accessed inorder), or several READ statements may accessthe same DATA statement. If the number ofvariables in exceeds thenumber of elements in the DATA statement(s), an"Out of data" error message is printed. If thenumber of variables specified is fewer than thenumber of elements in the DATA statement(s),subsequent READ statements will begin readingdata at the first unread element. If there areno subsequent READ statements, the extra data isignored.
To reread DATA statements from the start, usethe RESTORE statement (see "RESTORE;" Section2.57)
80 FOR I=l TO 1090 READ A(I)100 NEXT I110 DA.TA 3.08,5.19,3.12,3.98,4.24120 DATA 5.08,5.55,4.00,3.16,3.37
This program segment READs the valuesDATA statements into the arrayexecution, the value of A(l) will beso on.
from theA. After3.08, and
-
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-75
)
)
Example 2 LIST10 PRINT "CITY", "STATE", " ZIP"20 READ C$,S$,Z30 DATA "DENVER,", COLORADO, 8021140 PRINT C$,S$,ZOkRUNCITY STATE ZIPDENVER, COLORADO 80211Ok
This program READs string and numeric data fromthe DATA statement in line 30.
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2.55 REM
Format REM
Page 2-76
Purpose
Remarks
To allow explanatory remarks to be inserted in aprog ram.
REM statements are not executed but are outputexactly as entered when the program is listed.
REM statements may be branched into from a GOTOor GOSUB statement. Execution will continuewith the first executable statement after theREM statement.
Remarks may bepreceding themark instead of
added toremark:REM.
the end of a line bywith a single quotation
Important
Example
Do not use this in a data statement, because itwould be considered legal data.
120 REM CALCULATE AVERAGE VELOCITY130 FOR I=l TO 20140 SUM=SUM + V(I)
or
120 FOR I=l TO 20130 SUM=SUM+V(I)140 NEXT I
'CALCULATE AVERAGE VELOCITY
)
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2.56 RENUM
Page 2-77
)
Format
Purpose
Remarks
Note
RENUM [[] [,[] [,]]]
To renumber program lines.
is the first line number to be usedin the new sequence. The default is 10. is the line in the current program whererenumbering is to begin. The default is thefirst line of the program. is theincrement to be used in the new sequence. Thedefault is 10.
RENUM also changes all line number referencesfollowing GOTO, GOSUB, THEN, ON . GOTO,ON . GOSUB, and ERL statements to reflect thenew line numbers. If a nonexistent line numberappears after one of these statements, the errormessage "Undefined line number in xxxxx" isprinted. The incorrect line number reference isnot changed by RENUM, but line number yyyyy maybe changed.
RENUM cannot be used to change the order ofprogram lines (for example, RENUM 15,30 when theprogram has three lines numbered 10, 20 and 30)or to create line numbers greater than 65529.An "Illegal function call" error will result.
Examples RENUM
RENUM 300" 50
Renumbers the entire program.The first new line numberwill be 10. Lines will benumbered in increments of 10.
Renumbers the entire pro-gram. The first new linenumber will be 300. Lineswill be numbered inincrements of 50.
)
RENUM 1000,900,20 Renumbers the lines from900 up so they start withline number 1000 and arenumbered in increments of 20.
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2.57 RESTORE
Format RESTORE [ ]
Page 2-78
Purpose
Remarks
Example
To allow DA~ statements to be reread from aspecified line.
After a RESTORE statement is executed, the nextREAD statement accesses the first item in thefirst DA~ statement in the program. If is specified, the next READ statementaccesses the first item in the specified DATAsta temen t.
10 READ A,B,C20 RESTORE30 READ D,E,F40 DATA 57, 68, 79
)
)
-
MICROSOFT BASIC COMMkNDS AND STATD1ENTS
2.58 RESUHE
Page 2-79
Formats
Purpose
Remarks
RESUME
RESUME 0
RESUME NEXT
RESUME
To continue program execution after an errorrecovery procedure has been performed.
Anyone of the four formats shown above may beused, depending upon where execution is toresume:
RESUMEor
RESUME 0
RESUME NEXT
Execution resumes at thestatement which caused theerror.
Execution resumes at thestatement immediately fol-lowing the one whichcaused the error.
) RESO}lE Execution resumes at.
Example
A RESUME statement thathandling routine causes amessage to be printed.
10 ON ERROR GOTO 900
is not in an"RESUME wi thou t
errorerror"
)
900 IF (ERR=230) AND (ERL=90) THEN PRINT "TRYAGAIN" :RESUME 80
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2.59 RUN
Page 2-80
Format 1
Purpose
Remarks
Example
Format 2
Purpose
Remarks
RUN [ ]
To execute the program currently in memory.
If is specified, execution beginson that line. Otherwise, execution begins atthe lowest line number. Microsoft BASIC alwaysreturns to command level after a RUN isexecuted.
RUN
RUN [,R]
To load a file from disk into memory and run it.
is the name used when the file wasSAVEd. (Your opera ting ,system may append adefault filename extension if one was notsupplied in the SAVE command. Refer to"Microsoft BASIC Disk I/O," in the MicrosoftBASIC User's Guide for information aboutpossible filename extensions 'under youroperating system.)
Example
RUN closes all opencurrent contents ofdesignated program.option, all data files
RUN "NEWFIL",R
files and deletesmemory before loadingHowever, with therema in OPEN.
thethe"R"
Note
See also "Microsoft BASIC Disk I/O," in theMicrosoft BASIC User's Guide.
Microsoft BASIC Compiler supports the RUN andRUN forms of the RUN statement.Microsoft BASIC Compiler does not support the"R" option with RUN. If you want this feature,the CHAIN statement should be used.
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2.60 SAVE
Format SAVE [{,A!,P}]
Page 2-81
)
I
Purpose
Remarks
Examples
To save a program file on disk.
is a quoted string that conforms toyour operating system's requirements forfilenames. (Your operating system may append adefault filename extension if one was notsupplied in the SAVE command. Refer to"Microsoft BASIC Disk I/O," in the MicrosoftBASIC User's Guide for information aboutpossible filename extensions under youroperating system.) If already exists,the file will be written over.
Use the A option to save the file in ASCIIformat. Otherwise, Microsoft BASIC saves thefile in a compressed binary format. ASCIIformat takes more space on the disk, but somedisk access requires that files be in ASCIIformat. For instance, the MERGE commandrequires an ASCII format file, and someoperating system commands such as LIST mayrequire an ASCII format file.
Use the P option to protect the file by savingit in an encoded binary format. When aprotected file is later RUN (or LOADed), anyattempt to list or edit it will fail.
SAVE "COM2" ,ASAVE "PROG" , P
See also "Microsoft BASIC Disk I/O,"in the Microsoft BASIC User's Guide.
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2.61 STOP
Format STOP
Page 2-82
Purpose
Remarks
Example
To terminate program execution and return tocommand level.
STOP statements may be used anywhere in aprogram to terminate execution. When a STOP isencountered, the following message is printed:
Break in line nnnnn
Unlike the END statement, the STOP statementdoes not close files.
Microsoft BASIC always returns to command levelafter a STOP is executed. Execution is resumedby issuing a CONT command (see Section 2.8).
10 INPUT A,B,C20 K=A~2*5.3:L=B~3/.2630 STOP40 M=C*K+IOO:PRINT MRUN? 1,2,3BREAK IN 30OkPRINT L
30.7692OkCONT
115.9Ok
)
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2.62 SWAP
Format SWAP ,
Page 2-83
Purpose
Remarks
To exchange the values of two variables.
Any type variable may be SWAPped (integer,single precision, double precision, string), butthe two variables must be of the same type or a"Type mismatch" error results.
)
)
Example LIST10 A$=" ONE " : B$=" ALL "20 PRINT A$ C$ B$30 SWAP A$, B$40 PRINT A$ C$ B$RUNOk
ONE FOR ALLALL FOR ONE
Ok
C$=" FOR"
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2.63 TRON/TROFF
Format TRON
TROFF
Page 2-84
Purpose
Remarks
Example
To trace the execution of program statements.
As an aid in debugging, the TRON statement(executed in either direct or indirect mode)enables a trace flag that prints each linenumber of the program as it is executed .. Thenumbers appear enclosed in square brackets. Thetrace flag is disabled with the TROFF statement(or when a NEW command is executed).
TRONOkLIST10 K=lO20 FOR J=l TO 230 L=K + 1040 PRINT J;K;L50 K=K+lO60 NEXT70 ENDOkRUN[10) [20] [30) [40] 1 10 20[50) [60) [30) [40) 2 20 30[50] [601 [70)OkTROFFOk
)
)
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2.64 WAIT
Format WAIT ,I[,J]
where I and J are integer expressions.
Page 2-85
)
)
Purpose
Remarks
Important
Example
To suspend program execution while monitoringthe status of a machine input port.
The WAIT statement causes execution to besuspended until a specified machine input portdevelops a specified bit pattern. The data readat the port is exclusive ORled with the integerexpression J, and then AND'ed with I. If theresult is zero, Microsoft BASIC loops back andreads the data at the port again. If the resultis nonzero, execution continues with the nextstatement. If J is omitted, it is assumed to bezero
It is possible to enter an infinite loop withthe WAIT statement, in which case it will benecessary to manually restart the machine. Toavoid this, WAIT must have the specified valueat during some point in theprogram execution.
100 WAIT 32,2
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2.65 WHILE ... WEND
Format WHILE
[]
WEND
Page 2-86
Purpose
Remarks
Exa'llple
To execute a series of statements in a loop aslong as a given condition is true.
If is not zero (Le., true), are executed until the WENDstatement is encountered. Microsoft BASIC thenreturns to the WHILE statement and checks. If it is still true, the processis repeated. If it is not true, executionresumes with the statement following the WENDstatemen t.
WHILE/WEND loops may be nested to any level.Each WEND will match the most recent WHILE. Anunmatched WHILE statement causes a "WHILEwithout WEND" error, and an unmatched WENDstatement causes a "WEND without WHILE" error.
90 'BUBBLE SORT ARRAY A$100 FLIPS=l 'FORCE ONE PASS THRU LOOP110 WHILE FLIPS115 FLIPS=O120 FOR I=l TO J-l130 IF A$(IA$(I+l) THEN
SWAP A$(I),A$(I+l) :FLIPS=l140150 WEND
NEXT I
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2.66 WIDTH
Format WIDTH [LPRINT J
Page 2-87
Purpose
Remarks
To set the printed line width in number ofcharacters for the terminal or line printer.
If the LPRINT option is omitted, the line widthis set at the terminal. If LPRINT is included,the line width is set at the line printer.
range 15 to 255.characters.
must have aThe default
value in thewidth is 72
)
)
Example
If is 255, the line widthis "infinite"; that is, Microsoft BASIC neverinse rts a carr iage return. However, theposition of the cursor or the print head, asgiven by the POS or LPOS function, returns tozero after position 255.
10 PRINT "ABCDEFGHI JKLMNOPQRSTUVWXYZ"RUNABCDEFGHIJKLMNOPQRSTUVWXYZOkWIDTH 18OkRUNABCDEFGHIJKLMNOPQRSTUVWXYZOk
-
MICROSOFT BASIC CO~~ANDS AND STATEMENTS
2.67 WRITE
Format WRITE []
Page 2-88
Purpose
Remarks
To output data at the terminal.
If is omitted, a blankline is output. If isincluded, the values of the expressions areoutput at the terminal. The expressions in thelist may be numeric and/or string expressions.They must be separated by commas.
When the printed items are output, each item isseparated from the last by a comma. Printedstrings are delimited by quotation marks. Afterthe last item in the list is printed, MicrosoftBASIC inserts a carriage return/line feed.
WRITE outputs numericforma t as the PRINT2.49.)
values using the samestatement. (See Section
Example 10 A=80:B=90:C$="THAT'S ALL"20 WRITE A,B,C$RUN
80, 90 , "THAT'S ALL"Ok
)
-
MICROSOFT BASIC COMMANDS AND STATEMENTS
2 .68 WRITE?,
Page 2-89
Format WRITE#,
)
)
Purpose
Remarks
Example
To write data to a sequential file.
is the number under which the filewas OPENed in "0" mode (see "OPEN," Section2.45). The expressions in the list are stringor numeric expressions. They must be separatedby commas.
The difference between WRITE# and PRINT# is thatWRITE# inserts commas between the items as theyare written to disk and delimits strings withquotation marks. Therefore, it is not necessaryfor the user to put explicit delimiters in thelist. A carriage return/line feed sequence isinserted after the last item in the list iswritten to disk.
Let A$="CAMERA" and B$="93604-1"
The statement:
WRITE#! ,A$ ,B$
writes the following image to disk:
"CAMERA", "93604-1"
A subsequent INPUT# statement, such as
INPUT#! ,A$ ,B$
would input "CAMERA" to A$ and "93604-1" to B$.
-
)
-
)
)
Chapter 3 Microsoft BASIC Functions
Introduction3.1 ABS3.2 ASC3.3 ATN3.4 CDBL3.5 CHR$3.6 CINT3.7 COS3.8 CSNG3.9 CVI, CVS, CVD3.10 EOF3.11 EXP3.12 FIX3.13 FRE3.14 HEX$3.15 INKEY$3.16 INP3.17 INPUT$3.18 INSTR3.19 INT3.20 LEFT$3.21 LEN3.22 LOC3.23 LOG3.24 LPOS3.25 MID$3.26 MIK$, MKS$, MKD$3.27 OCT$3.28 PEEK3.29 POS3.30 RIGHT$3.31 RND3.32 . SGN3.33 SIN3.34 SPACES3.35 SPC3.36 SQR3.37 STR$3.38 STRING$3.39 TAB3.40 TAN3.41 USR3.42 VAL3.43 VARPTR
-
)
-
CHAPTER 3
MICROSOFT BASIC FUNCTIONS
Microsoft BASICchapter. Thewithout further
intrinsic functionsfunctions may bedefinition.
are described in thiscalled from any program
Arguments to functions are always enclosed inIn the formats given for the functions in thisarguments have been abbreviated as follows:
paren theses.chapter, the
)
X and Y
I and J
X$ and Y$
Represent any numeric expressions.
Represent integer expressions.
Represent string expressions.
If a floating-point value is supplied where an integer isrequired, Microsoft BASIC will round the fractional portionand use the resulting integer.
)
Note With Microsoft BASIC Interpreter,single precision results are returned byprecision functions are supported onlyBASIC Compiler.
only in teg e randfunctions. Doubleby the Microsoft
-
MICROSOFT BASIC FUNCTIONS
3.1 ABS
Page 3-2
Format
Action
Example
3.2 ASC
Format
Action
Example
ABS(X)
Returns the absolute value of the expression X.
PRINT ABS(7*(-535
Ok
ASC(X$)
Returns a numerical value that is the ASCII codefor the first character of the string X$. (SeeAppendix C for ASCII codes.) If X$ is null, an"Illegal function call" error is returned.
10 X$="TEST"20 PRINT ASC (X$)RUN
84Ok
See the CHR$ function, Section 3.5, for detailson ASClI-to-string conversion.
-
MICROSOFT BASIC FUNCTIONS
3.3 ATN
Page 3-3
)
/
Format
Action
Example
3.4 CDBL
Format
Action
Example
ATN (Xl
Returns the arctangent of X in radians. Resultis in the range -pi/2 to pi/2. The expression Xmay be any numeric type, but the evaluation ofATN is always performed in single precision.
10 INPUT X20 PRINT ATN (XlRUN? 31.24905
Ok
CDBL (X)
Converts X to a double precision number.
10 A=454.6720 PRINT A;CDBL (A)RUN
454.67 454.6700134277344Ok
-
MICROSOFT BASIC FUNCTIONS
3.5 CHR$
Page 3-4
Format
Action
Example
3.6 CINT
Format
Action
Example
CHR$(I)
Returns a string whose one character is ASCIIcharacter I. (ASCII codes are listea inAppendix C.) CHR$ is commonly used to send aspecial character to the terminal. Forinstance, the BEL character (CHR$(7)) could besent as a preface to an error message, or a formfeed (CHR$(12 could be sent to clear aterminal screen and return the cursor to thehome position.
PRINT CHR$ (66)BOk
See the ASC function, Section 3.2, for detailson ASClI-to-numeric conversion.
CINT (X)
Converts X to an integer by rounding thefractional portion. If X is not in the range-32768 to 32767, an "Overflow" error occurs.
PRINT CINT(45.67)46
Ok
See the CDBL and CSNG functions for details onconverting numbers to the double precision andsingle precision data type, respectively. Seealso the FIX and INT functions, both of whichreturn integers.
)
)
-
MICROSOFT BASIC FUNCTIONS
3.7 COS
Page 3-5
Format
Action
COS (Xl
Returns thecalculationprecision.
cosine ofof COS (Xl
Xis
in radians. Theperformed in single
)
)
Example
3.8 CSNG
Format
Action
Example
10 X=2*COS {. 4 l20 PRINT XRUN
1.84212Ok
CSNG (Xl
Converts X to a single precision number.
10 Ai = 975.3421#20 PRINT A#: CSNG(A#)RUN
975.3421 975.341Ok
See the CINT and CDBL functions for convertingnumbers to the integer and double precision datatypes, respectively.
-
MICROSOFT BASIC FUNCTIONS
3 .9 CVI, CVS, CVD
Page 3-6
Format
Action
-Example
3.10 EOF
CVI2-byte stringCVS4-byte stringCVD8-byte string
Convert string values to numeric values.Numeric values that are read in from a randomdisk file must be converted from strings backinto numbers. CVI converts a 2-byte string toan integer. CVS converts a 4-byte string to asingle precision number. CVD converts an 8-bytestring to a double precision number.
70 FIELD 11,4 AS N$, 12 AS B$, ...80 GET 1190 Y=CVS (N$)
See also nMKI$, MKS$, MKD$," Section 3 .26 and"Microsoft BASIC Disk I/O," in the MicrosoftBASIC User's Guide. )
Format EOFfile number
Action
Example
Returns -1 (true) if the end of a sequentialfile has been reached. Use EOF to test forend-of-file while INPUTting, to avoid "Inputpast end" errors.
10 OPEN "I",l,"DATA"20 C=O30 IF EOF(l) THEN 10040 INPUT Il,M(C)50 C=C+l:GOTO 30
)
-
MICROSOFT BASIC FUNCTIONS
3.11 EXP
Format EXP(X)
Page 3-7
Action Returns e (base of natural logarithms) to thepower of X. X must be
-
MICROSOFT BASIC FUNCTIONS
3.13 FRE
Format FRE(O)FRE(UU)
Page 3-8
Action Arguments to FRE are dummyreturns the number of bytes inused by Microsoft BASIC.
arguments. FREmemory not being
FRE (U U) forcesreturning thepatient: garbageminutes.
a garbage collection beforenumber of free bytes. Becollection may take 1 to 1-1/2
Microsoft BASIC willcollection until allup. Therefore, usingresult in shortercollection.
not initiate garbagefree memory has been used
FRE(U") periodically willdelays for each garbage
Example
3.14 HEX$
PRINT FRE(O)14542
Ok
Format HEX$(X)
Action Returns ahexadecimalrounded toevaluated.
string which representsvalue of the decimal argument.
an integer before HEX$(X)
theX is
is
Example 10 INPUT X20 A$=HEX$ (X)30 PRINT X "DECIMAL IS U A$ U HEXADECIMAL uRUN? 32
32 DECIMAL IS 20 HEXADECIMALOk
See the OCT$ function, Section 3.27, for detailson octal conversion.
-
MICROSOFT BASIC FUNCTIONS
3.15 INKEY$
Format INKEY$
Page 3-9
Action Returns either a one-character string containinga character read from the terminal or a nullstring if no character is pending at theterminal. No characters will be echoed. Allcharacters are passed through to the programexcept for Control-C, which terminates theprogram. (With Microsoft BASIC Compiler,Control-C is also passed through to theprogram. )
)
Example
3.16 INP
Format
1000 'TIMED INPUT SUBROUTINE1010 RESPONSE$=""1020 FOR 1%=1 TO TIMELIMIT%1030 A$=INKEY$ : IF LEN(A$)=O THEN 10601040 IF ASC(A$)=13 THEN TIMEOUT%=O : RETURN1050 RESPONSE$=RESPONSE$+A$1060 NEXT 1%1070 TIMEOUT%=l : RETURN
INP (I)
Action Returns thethe rangefunction to
byte read from port I. I must be ino to 255. INP is the complementarythe OUT statement, Section 2.47.
)
Example 100 A=INP(255)
-
MICROSOFT BASIC FUNCTIONS
3.17 INPUT$
Format INPUT$(X[,[#]Y])
Page 3-10
Action Returns a string of X characters, read from theterminal or from file number Y. If the terminalis used for input, no characters will be echoed.All control characters are passed through exceptControl-C, which is used to interrupt theexecution of the INPUT$ function.
Example 1
Example 2
5 'LIST THE CONTENTS OF A SEQUENTIAL FILE INHEXADECIMAL100PEN"I",1,"DATA"20 IF EOF(l) THEN 5030 PRINT HEX$(ASC(INPUT$(l,#l)));40 GOTO 2050 PRINT60 END
100 PRINT "TYPE P TO PROCEED OR S TO STOP"no X$=INPUT$ (1)120 IF X$="P" THEN 500130 IF X$="S" THEN 700 ELSE 100 )
)
-
MICROSOFT BASIC FUNCTIONS
3.18 INSTR
Format INSTR ([I, 1X$, Y$)
Page 3-11
Action Searches for the first occurrence of string Y$in X$, and returns the position at which thematch is found. Optional offset I sets theposition for starting the search. I must be inthe range 1 to 255. If I is greater than thenumber of characters in X$ (LEN(X$, or if X$is null or Y$ cannot be found, INSTR returns O.If Y$ is null, INSTR returns I or 1. X$ and Y$may be string variables, string expressions, orstring literals.
)
)
Example
Note
10 X$="ABCDEB"20 Y$="B"30 PRINT INSTR(X$,Y$) ;INSTR(4,X$,Y$)RUN
2 6Ok
If I=O is specified, the "Illegal function call"error message will be returned.
-
MICROSOFT BASIC FUNCTIONS
3.19 INT
Forma t INT (X)
Action Returns the largest integer
-
MICROSOFT BASIC FUNCTIONS
3.21 LEN
Format LEN (X$)
Page 3-13
Action Returns the number of characters in X$.Nonprinting characters and blanks are counted.
Example
3.22 LOC
10 X$=" PORTLAND, OREGON"20 PRINT LEN (X$)
16Ok
Format LOCfile number
where is the number under whichthe file was OPENed.
)
)
Action
Example
With random disk files, LOC returns the recordnumber just read or written from a GET or PUTstatement. If the file was opened but no diskI/O has been performed yet, LOC returns a O.With sequential files, LOC returns the number ofsectors (128-byte blocks) read from or writtento the file since it was OPENed.
200 IF LOC(150 THEN STOP
-
MICROSOFT BASIC FUNCTIONS
3.23 LOG
Format LOG (X)
Page 3-14
Action
Example
3.24 LPOS
Returns the natural logarithm of X. X must begreater than zero.
PRINT LOG (45/7)1.86075
Ok
Format LPOS(X)
Action Returns the current position of the line printerprint head within the line printer's buffer.Does not necessarily give the physical positionof the print head. X is a dummy argument.
Example 100 IF LPOS(X60 THEN LPRINT CHR$(13)
)
-
MICROSOFT BASIC FUNCTIONS
3.25 MID$
Format MID$(X$,I[,J))
Page 3-15
)
)
Action
Example
Returns a string of length J characters from X$,beginning with the Ith character. I and J mustbe in the range 1 to 255. If J is omitted or ifthere are fewer than J characters to the rightof the Ith character, all rightmost charactersbeginning with the Ith character are returned.If I is greater than the number of characters inX$ (LEN(X$)), MID$ returns a null string.
LIST10 A$="GOOD "20 B$="MORNING EVENING AFTERNOON"30 PRINT A$;MID$(B$,9,7)OkRUNGOOD EVEN INGOk
Also see the LEFT$ and RIGHT$ functions,Sections 3.20 and 3.30, respectively.
If I=O is spes: if ied, the "Illegal function call"error message will be returned.
-
MICROSOFT BASIC FUNCTIONS
3.26 MKI$, MKS$, MKD$
Format MKI$integer expressionMKS$single precision expressionMKD$double precision expression
Page 3-16
Action Convert numeric values to string values. Anynumeric value that is placed in a random filebuffer with an LSET or RSET statement must beconverted to a string. MKI$ converts an integerto a 2-byte string. MKS$ converts a singleprecision number to a 4-byte string. MKD$converts a double precision number to an 8-bytes tr il'\g .
Example 90 AMT= (K+T)100 FIELD *1,8 AS D$,20 AS N$110 LSET D$=MKS$(AMT)120 LSET N$=A$130 PUT U
See also "CVI, CVS,"Microsoft BASIC DiskBASIC User's Guide.
CVD,I1
I/O, "Section 3.9 and
in the Microsoft
-
MICROSOFT BASIC FUNCTIONS
3.27 OCT$
Format OCT$(X}
Page 3-17
Action
Example
3.28 PEEK
Returns a string which represents the octalvalue of the decimal argument. X is rounded toan integer before OCT$(X) is evaluated.
PRINT OCT$ (24)30
Ok
See the HEX$ function, Section 3.14, for detailson hexadecimal conversion.
Format PEEK(I}
)
.J
Action
Remarks
Example
Returns the byte read from the indicated memorylocation (I).
The returned value is an integer in the range 0to 255. I must be in the range -32768 to 65535.(For the interpretation of a negative value ofI, see "VARPTR," Section 3.43.)
PEEK is the complementary function of the POKEsta temen t.
A=PEEK (&H5AOO)
-
MICROSOFT BASIC FUNCTIONS
3.29 POS
Format POS(I)
Page 3-18
Action Returns the current cursor position. Theleftmost position is 1. X is a dummy argument.
Example IF POS(X60 THEN PRINT CHR$(13)
Also see the LPOS function, Section 3.24.
3.30 RIGHT$
Format RIGHT$(X$,I)
Action Returns the rightmost I characters of string X$.If I is equal to the number of characters in X$(LEN(X$)), returns X$. If I=O, the null string(length zero) is returned.
Example 10 A$="DISK BASIC"20 PRINT RIGHT$(A$,5)~N
BASICOk
Also see the LEFT$ and MID$ functions, Sections3.20 and 3.25, respectively.
)
-
MICROSOFT BASIC FUNCTIONS
3.31 RND
Forma t RND [ (X) 1
Page 3-19
Action Returns a random number between 0 and 1. Thesame sequence of random numbers is generatedeach time the program is RUN unless the randomnumber generator is reseeded (see "RANDOMIZE,"section 2.53). However, XO ornumbernumber
X omitted generates the next randomin the sequence. X=O repeats the last
generated.
Example
Note
)
3.32 SGN
Format
Action
. Example
)
10 FOR I=l TO 520 PRINT INT(RND*lOO);30 NEXTRUN
24 30 31 51 5Ok
The values produced by the RND functionmay vary with different implementations ofMicrosoft BASIC.
SGN (X)
If X>O, SGN(X) returns 1.If X=O, SGN(X) returns O.If X
-
MICROSOFT BASIC FUNCTIONS
3.33 SIN
Format SIN (X)
Page 3- 20
Action
Example
Returns the sine of X incalculated inCOS(X)=SIN(X+3.14159/2) .
PRINT SIN(1.5).997495
Ok
radians.single
SIN (X) isprec is ion.
See also the COS (X) function, Section 3.7.
3.34 SPACE$
Format SPACE$(X)
Action Returns a string of spaces of length X. Theexpression X is rounded to an integer and mustbe in the range 0 to 255.
Example 10 FOR I=l TO 520 X$=SPACE$(I)30 PRINT X$; I40 NEXT IRUN
12
34
5Ok
Also see the SPC function, Section 3.35.
)
)
-
MICROSOFT BASIC FUNCTIONS
3.35 SPC
Format SPC(I)
Page 3-21
Action Prints I blanks on the terminal. SPC may onlybe used with PRINT and LPRINT statements. Imust be in the range 0 to 255. A'; I is assumedto follow the SPC(I) command.
Example
3.36 SQR
PRINT "OVER" SPC (15) "THERE"OVER THEREOk
Also see the SPACES function, Section 3.34.
Format SQR(X)
Action Returns the square root of X. X must be >=0.
)
)
Example 10 FOR X=lO20 PRINT X,30 NEXTRUN
10152025
Ok
TO 25 STEP 5SQR (X)
3.162283.872984.472145
-
MICROSOFT BASIC FUNCTIONS
3.37 STR$
Format STR$(X)
Page 3-22
Action
Example
Returns a string representation of the value ofX.
5 REM ARITHMETIC FOR KIDS10 INPUT "TYPE A NUMBER"; N20 ON LEN(STR$(N) GOSUB 30,100,200,300,400,500
Also see the VAL function, Section 3.42.
3.38 STRING$
Formats
Action
Example
STRING$ (I ,J)STRING$ (I ,X$)
Returns a string of length I whose charactersall have ASCII code J or the first character ofX$ .
10 X$=STRING$ (10 ,45)20 PRINT X$ "MONTHLY REPORT" X$RUN----------MONTHLY REPORT----------Ok
)
-
MICROSOFT BASIC FUNCTIONS
3.39 TAB
Format TAB(Il
Page 3-23
Action Spaces to position I on the terminal. If thecurrent print position is already beyond spaceI, TAB goes to that position on the next line.Space 1 is the leftmost position, and therightmost position is the width minus one. Imust be in the range 1 to 255. TAB may only beused in PRINT and LPRINT statements.
Example 10 PRINT "NAJ1E" TAB (25 1 "AMOUNT" : PRINT20 READ A$ ,B$30 PRINT A$ TAB(25l B$40 DATA "G. T. JONES", "$25 .00"RUNNAME AMOUNT
)3.40 TAN
Format
G. T. JONESOk
TAN (X)
$25.00
)
Action
Example
Returns the tangent of X in radians. TAN (Xl iscalculated in single precision. If TANoverflows, the "Overflow" error message isdisplayed, machine infinity with the appropriatesign is supplied as the result, and executioncontinues.
10 Y=Q*TAN(Xl/2
-
MICROSOFT BASIC FUNCTIONS
3.41 USR
Format USR[l (X)
Page 3-24
Action Calls the user's assembly language subroutinewith the argument X. is in the range 0to 9 and corresponds to the digit supplied withthe DEF USR statement for that routine. If is omitted, USRO is assumed. See"Assembly Language Subroutines," in theMicrosoft BASIC User's Guide.
Format VAL(X$)
Example
3.42 VAL
Action
40 B=T*SIN (Y)50 C=USR (B/2)60 D=USR(B/3)
Returns the numerical value of string X$.VAL function also strips leading blanks,and linefeeds from the argument string.example,
VAL (" -3")
returns -3.
Thetabs,
For
)
Example 10 READ NAME$,CITY$,STATE$,ZIP$20 IF VAL(ZIP$)
-
MICROSOFT BASIC FUNCTIONS
3.43 VARPTR
Page 3-25
)
)
Format 1
Format 2
Action
Note
Example
VARPTRvariable name
VARPTR{#
-
)
)
-
)
)
MICROSOFT BASIC FUNCTIONS
Appendices
A Error Codes and Error MessagesB Mathematical FunctionsC ASCII Character CodesD Microsoft BASIC Reserved Words
-
)
-
)
Code
NF
APPENDIX A
Error Codes and Error Messages
Number Message
I NEXT without FOR
SN 2
A variable in a NEXTcorrespond to anyunmatched FOR statement
Syntax error
statementpreviouslyvariable.
does notexecuted,
)
RG 3
A line is encountered that contains someincorrect sequence of characters (such asunmatched parenthesis, misspelled command orstatement, incorrect punctuation, etc.).Microsoft BASIC automatically enters editmode at the line that caused the error.
Return without GOSUB
00 4
A RETURN statement is encountered forthere is no previous, unmatchedstatement.
Out of data
whichGOSUB
FC 5
A READ statement is executed when there areno DATA statements with unread data remainingin the program.
Illegal function call
A parameter that is out of range is passed toa math or string function. An FC error mayalso occur as the result of:
)
1. A negativesubscript.
or unre asonably large
-
OV
OM
UL
BS
6
7
8
9
Page A-2
2. A negative or zero argument with LOG.
3. A negative argument to SQR.
4. A negative mantissa with a nonintegerexponen t.
5. A call to a USR function for which thestarting address has not yet been given.
6. An improper argument to MID$, LEFT$,RIGHT$, INP, OUT, WAIT, PEEK, POKE, TAB,SPC, STRING$, SPACE$, INSTR, orON ... GOTO.
Overflow
The result of a calculation is too large tobe represented in Microsoft BASIC numberformat. If underflow occurs, the result iszero and execution continues without anerror.
Out of memory
A program is too large, or has too many FORloops or GOSUBs, too many variables, orexpressions that are too complicated.
Undefined line
A nonexistent line is referenced in a GOTO,GOSUB, IF ... THEN .. ELSE, or DELETE statement.
Subscript out of range
An array elementsubscript thatthe array orsubscripts.
is referenced either withis outside the dimensions
with the wrong number
aofof
DD
/0
10
11
Redimensioned array
Two DIM statements are given for the samearray; or, a DIM statement is given for anarray after the default dimension of 10 hasbeen established for that array.
Division by zero
A division by zero is encountered in anexpression; or, the operation of involutionresults in zero being raised to a negativepower. Machine infinity with the sign of thenumerator is supplied ~s the result of the
)
-
ID 12
division, or positivesupplied as the resultexecution continues.
Illegal direct
Page A-3
machine infinity isof the involution, and
)
TM
as
LS
ST
13
14
15
16
A statement that is illegal in direct mode isentered as a direct mode command.
Type mismatch
A string variable name is assigned a numericvalue or vice versa; a function that expectsa numeric argument is given a string argumentor vice versa.
Out of string space
String variables have caused BASIC to exceedthe amount of free memory remaining.Microsoft BASIC will allocate string spacedynamically, until it runs out of memory.
String too long
An attempt is made to create a string morethan 255 characters long.
String formula too complex
CN 17
A string expression iscomplex. The expressioninto smaller expressions.
Can't continue
too long or tooshould be broken
UF 18
An attempt is made to continue a programthat:
1. Has halted due to an error.
2. Has been modified during a break inexecution.
3. Does not exist.
Undefined user function
A USR function is called before the functiondefinition (DEF statement) is given.
)
19 No RESUME
An error handling routine is entered butcontains no RESUME statement.
-
Page A-4
20 RESUME without error
A RESUME statement is encountered before anerror handling routine is entered.
21 Unprintable error
An error message is not available for theerror condition which exists.
22 Missing operand
An expression contains an operator with nooperand following it.
23 Line buffer overflow
An attempt has been made to input a line thathas too many characters.
26 FOR without NEXT
A FOR statement was encountered without amatching NEXT.
29 WHILE without WEND
A WHILE statement does not have a matchingWEND.
30 WEND without WHILE
A WEND statement was encountered without amatching WHILE.
Disk Errors
50 Field overflow
A FIELD statement is attempting to allocatemore bytes than were specified for the recordlength of a random file.
51 Internal error
)
An internal malfunctionMicrosoft BASIC. Reportconditions under which the
52 Bad file number
has occurred into Microsoft the
message appeared.
A statement or command references a file witha file number that is not OPEN or is out ofthe range of file numbers specified at
)
-
53
Page A-5
initialization.
File not found
A LOAD, KILL, or OPEN statement references afile that does not exist on the current disk.
54 Bad file mode
An attempt is made to use PUT, GET, or LOFwith a sequential file, to LOAD a randomfile, or to execute an OPEN statement with afile mode other than I, 0, or R.
55 File already open
A sequential output mode OPEN statement isissued for a file that is already open; or aKILL statement is given for a file that isopen.
57 Disk I/O error
)
)
An I/O error occurred on a diskoperation. It is a fatal error; i.e.,operating system cannot recover fromerror.
I/Oilieilie
-
Page A-6
58 File already exists
The filename specified in a NAME statement isiden tical to a filename already in use on thedisk.
61 Disk full
All disk storage space is in use.
62 Input past end
An INPUT statementdata in the filenull (empty) file.the EOF function to
63 Bad record number
is executed after all thehas been INPUT, or for a
To avoid this error, usedetect the end-of-file.
In a PUT oris either(32 ,767) or
GET statement, the recordgreater than the maximumequal to zero.
numberallowed
64 Bad file name
An illegal form is used for the filename witha LOAD, SAVE, KILL, or OPEN statement (e.g.,a filename with too many characters).
66 Direct statement in file
)
A direct statement isLOADing an ASCII-formatterminated.
67 Too many files
encountered whilefile. The LOAD is
An attempt is made to create a new file(using SAVE or OPEN) when all 255 directoryentries are full.
)
-
APPENDIX B
Mathematical Functions
Derived Functions
Functions that are not intrinsic to Microsoft BASIC may becalculated as follows.
Function Microsoft BASIC Equivalent
)
)
SECANTCOSECANTCOTANGENTINVERSE SINEINVERSE COSINEINVERSE SECANT
INVERSE COSECANT
INVERSE COTANGENTHYPERBOLIC SINEHYPERBOLIC COSINEHYPERBOLIC TANGENT
HYPERBOLIC SECANTHYPERBOLIC COSECANTHYPERBOLIC COTANGENT
INVERSE HYPERBOLICSINEINVERSE HYPERBOLICCOSINEINVERSE HYPERBOLICTANGENTINVERSE HYPERBOLICSECA."lTINVERSE HYPERBOLICCOSECANTINVERSE HYPERBOLICCOTANGENT
SEC (X) =l/COS (X)CSC (X) =l/SIN (X)COT(X)=l/TAN(X)ARCSIN (X)=ATN(X/SQR(-X*X+lARCCOS(X)=-ATN(X/SQR(-X*X+l+l.5708ARCSEC(X)=ATN(X/SQR(X*X-l
+SGN(SGN(X)-l)*l.5708ARCCSC(X)=ATN(X/SQR(X*X-l
+(SGN(X)-l)*l.5708ARCCOT(X)=ATN(X)+l.5708SINH(X)=(EXP(X)-EXP(-X/2COSH(X)=(EXP(X)+EXP(-X/2
TANH(X)=(EXP(X)-EXP(-X/(EXP(X)+EXP(-X) )
SECH(X)=2/(EXP(X)+EXP(-XCSCH(X)=2/(EXP(X)-EXP(-X
COTH(X)=(EXP(X)+EXP(-X/(EXP(X)-EXP(-X
ARCSINH(X)=LOG(X+SQR(X*X+l
ARCCOSH(X)=LOG(X+SQR(X*X-l)
ARCTANH(X)=LOGl+X)/(l-X/2
~~CSECH(X)=LOGSQR(-X*X~l)+l)/X)
ARCCSCH(X)=LOGSGN(X)*SQR(X*X+l)+l)/X)
ARCCOTH(X)=LOGX+l)/(X-l/2
-
)
)
-
APPENDIX C
ASCII Character Codes
Dec Hex CHR Dec Hex CHR Dec HexCHR
000 OOH NUL 043 2BH + 086 56HV
001 OlH SOH 044 2CH 087 57HW
002 02H STX 045 2DH 088 58HX
003 03H ETX 046 2EH 089 59Hy
004 04H EaT 047 2FH I 090 5AH
) Z005 OSH ENQ 048 30H 0 091 5BH[
006 06H ACK 049 31H 1 092 5CH\
007 07H BEL 050 32H 2 093 SOH1
008 08H BS 051 33H 3 094 5EHA
009 09H HT 052 34H 4 095 5FH
010 OAB LF 053 35H 5 096 60B
011 OBB VT 054 36H 6 097 61Ha
012 OCH FF 055 37H 7 098 62Hb
013 ODH CR 056 38H 8 099 63Hc
014 OEH SO 057 39H 9 100 64Hd
015 OFH SI 058 3AB 101 65He
016 10H DLE 059 3BH 102 66Bf
017 llH DCl 060 3CH < 103 67H
) g018 12H DC2 061 3DH = 104 68H
h
-
019 l3H DC3 062 3EH > 105 69Hi
020 14H DC4 063 3FH ? 106 6AHj
021 15H NAK 064 40H @ 107 6BHk
022 16H SYN 065 41H A lOB 6CH1
023 17H ETB 066 42H B 109 6DHm
024 1BH CAN 067 43H C 110 6EHn
025 19H EM 068 44H D 111 6FH0
026 1AH SUB 069 45H E 112 70HP
027 1BH ESCAPE 070 46H F 113 7lHq
028 1CH FS 071 47H G 114 72Hr
029 IDH GS 072 48H H 115 73Hs
030 1EH RS 073 49H I 116 74Ht
031 1FH US 074 4AH J 117 75Hu
032 20H SPACE 075 4BH K 118 76H )v033 21H 076 4CH L 119 77H
w034 22H n 077 4DH M 120 78H
x035 23H 4! 078 4EH N 121 79H
Y036 24H $ 079 4FH a 122 7AH
z038 26H & 0.81 51H Q 124 7CH
I039 27H 082 52H R 125 7DH
)040 28H 083 53H S 126 7EH
041 29H 084 54H T 127 7FHDEL
042 2AH * 085 55H U
Dec=decima1, Hex=hexadecima1 (Hl , CHR=character,LF=Line Feed, FF=Form Feed, CR=Carriage Return, DEL=Rubout
)
-
APPENDIX D
MICROSOFT BASIC RESERVED WORDS
The following is a list of reserved words used in MicrosoftBASIC.
ABS ER.ll,.SE LOF RIGHT$AND ERL LOG RNDASC ERR LPOS RSETATN ERROR LPRINT RUNAUTO END LSET SAVECALL EXP MERGE SBNCDBL FIELD MID$ SIN
) CHAIN FILES $MKD$ SPACECHR$ FIX MKI$ SPCCINT FOR M.T
-
)
)
-
INDEX
ABS 3-2Addition 1-10ALL 2-4, 2-10Arctangent 3-3Array variables 1-7, 2-10, 2-21Arrays 1-7, 2-8, 2-13, 2-27ASC 3-2ASCII codes 3-2, 3-4ASCII format 2-5, 2-53, 2-81Assembly language subroutines 2-3, 2-19, 2-63, 3-24 to 3-25ATN . 3-3AUTO . 1-2, 2-2Boolean operators 1-13
CALL 2-3Carriage return 1-3, 2-40, 2-45 to 2-46,2-87 to 2-89
Cassette tape 2-8, 2-13CDBL 3-3CHAIN 2-4, 2-10) Character set 1-3CHR$ 3-4CINT 3-4CLE.l>,R 2-7CLOAD