Microsoft Basic 8086xenix Reference PDF
Microsoft Basic 8086xenix Reference PDF
Reference Manual
Microsoft Corporation
)
Information in this document is subject to change without
notice and does not represent a commitment on the part of
Microsoft Corporation. The software described in this
document is furnished under a license agreement or
non-disclosure agreement. The software may be used or
copied only in accordance with the terms of the agreement.
'It is against the law to copy Microsoft (TM) BASIC on
magnetic tape, disk, or any other medium for any purpose
other than the purchaser's personal use.
Microsoft Corporation
Microsoft Building
10700 Northup Way
C-97200
Bellevue, Washington 98004
Introduction
Chapters 1 General Information about Microsoft BASIC
1.1 Initialization
1.2 Modes of Operation
1.3 Line Format
1.4 Character Set
1.5 Constants
1.6 Variables
1.7 Type Conversion
1.8 Expressions and Operators
1.9 Input Editing
1.10 Error Messages
)
2 Microsoft BASIC Commands and Statements
2.1 AUTO
2.2 CALL
2.3 CHAIN
2.4 CLEAR
2.5 CLOAD
2.6 CLOSE
2.7 COMMON
2.8 CONT
2.9 CSAVE
2.10 DATA
2.11 DEF FN
2.12 DEFINT/SNG/DBL/STR
2.13 DEF USR
2.14 DELETE
2.15 DIM
2.16 EDIT
2.17 END
2.18 ERASE
2.19 ERR and ERL Variables
2.20 ERROR
2.21 FIELD
2.22 FOR •.• NEXT
) 2.23
2.24
GET
GOSUB ..• RETURN
2.25 GOTO
2.26 IF ... THEN[ ..• ELSE] and IF .•. GOTO
2.27 INPUT
2.28 INPUTi!
2.29 KILL
2.30 LET
2.31 LINE INPUT
2.32 LINE INPUTi!
2.33 LIST
2.34 LLIST
2.35 LOAD
2.36 LPRINT and LPRINT USING
2.37 LSET and RSET
2.38 MERGE
2.39 MID$
2.40 NAME
2.41 NEW
2.42 NULL
2.43 ON ERROR GOTO
2.44 ON ••. GOSUB and ON ... GOTO
2.45 OPEN
2.46 OPTION BASE
2.47 OUT
2.48 POKE
2.49 PRINT
2.50 PRINT USING
2.51 PRINTi! and PRINTi! USING
2.52 PUT
2.53 RANDOMIZE
2.54 READ
2.55 REM
2.56 RENUM
2.57 RESTORE
2.58 RESUME
2.59 RUN
2.60 SAVE
2.61 STOP
2.62 SWAP
2.63 TRON!TROFF
2.64 WAIT
2.65 WHILE ..• WEND
2.66 WIDTH
2.67 WRITE
2.68 WRITE!i
3 Microsoft BASIC Functions
3.1 ABS
3.2 ASC
3.3 ATN
3.4 CDBL
3.5 CHR$
3.6 CINT
3.7 COS
3.8 CSNG
3.9 CVI, CVS, CVD
3.10 EOF
3.11 EXP
3.12 FIX
3.13 FRE
3.14 HEX$
3.15 INKEY$
3.16 INP
3.17 INPUT$
3.18 INSTR
3.19 INT
3.20 LEFT$
3.21 LEN
3.22 LOC
3.23 LOG
3.24 LPOS
3.25 MID$
3.26 MIK$, MKS$, MKD$
3.27 OCT$
3.28 PEEK
3.29 POS
3.30 RIGHT$
3.31 RND
3.32 SGN
3.33 SIN
3.34 SPACE$
3.35 SPC
3.36 SQR
) 3.37
3.38
STR$
STRING$
3.39 TAB
3.40 TAN
3.41 USR
3.42 VAL
3.43 VARPTR
B Mathematical Functions
Index
)
)
)
In troduction
)
Chapter 1 General Information about Microsoft BASIC
1.1 Initialization
1. 5 Cons tan ts
)
)
CHAPTER 1
1.1 INITIALIZATION
The procedure for initialization will vary with different
implementations of Microsoft BASIC. Check the Microsoft
BASIC User's Guide for your machine to determine how
Microsoft BASIC is initialized with your operating system.
)
GENERAL INFORMATION ABOUT MICROSOFT BASIC Page 1-3
Blank
= Equals sign or assignment symbol
+ plus sign
Minus sign
* Asterisk or multiplication symbol
/
A
Slash or division symbol
Up arrow or exponentiation symbol
( Left parenthesis
) Right parenthesis
% Percent
) i
$
Number (or pound) sign
Dollar sign
! Exclamation point
[ Left bracket
1 Right bracket
Comma
Period or decimal point
Single quotation mark (apostrophe)
., Semicolon
: Colon
& Ampersand
? Question mark
< Less than
> Greater than
\ Backslash or integer division symbol
@ At sign
Underscore
<rubout> Deletes last character typed.
<escape> Escapes edit mode subcommands.
See Section 2.16.
<tab> Moves print position to next tab stop.
Tab stops are set every eight columns.
<line feed> Moves to next physical line.
<carriage
return> Terminates input of a line.
)
GENERAL INFORMATION ABOUT.MICROSOFT BASIC Page 1-4
1.5 CONSTANTS
&H76
&H32F
5. Octal constants Octal numbers, denoted by the
prefix &0 or &.
Examples:
&0347
&1234
Note The 8K version of Microsoft BASIC does not support
hexadecimal or octal constants.
)
GENERAL INFORMATION ABOUT MICROSOFT BASIC Page 1-6
Examples:
46.8
-1.09E-06
3489.0
22.5!
Examples:
345692811
-1.09432D-06
3489.0i
7654321.1234
1.6 VARIABLES
% Integer variable
) Single precision variable
Integer 2
Single Precision 4
Double Precision 8
Arrays Type Bytes
Integer 2 per element
Single Precision 4 per elemen t
Double Precision 8 per elemen t
Strings
10 A%=23.42
20 PRINT A%
RUN
23
GENERAL INFORMATION ABOUT MICROSOFT BASIC Page 1-9
1. Ar i thmetic
2. Relational
3. Logical
4. Functional
Negation -X
(X
X
X(-Y) X*(-Y) Two consecutive
operators must
be separated by
parentheses.
Example:
10.4 MOD 4=2 (10/4=2 with a remainder 2)
25.68 MOD 6.99=5 (26/7=3 with a remainder 5)
Modulus arithmetic follows integer division in order of
) precedence.
GENERAL INFORMATION ABOUT MICROSOFT BASIC Page 1-12
= Equality X=Y
<> Inequality x<>y
More examples:
)
GENERAL INFORMATION ABOUT MICROSOFT BASIC Page 1-14
AND
X y X AND Y
1 1 1
1 o o
o 1 o
o o o
OR
X Y X OR Y
1 1 1
1 o 1
o 1 1
o o o
XOR
X Y X XOR Y
1 1 o
1 o 1
o 1 1
o o o
EQV
X Y X EQV Y
1 1 1
1 o o
o 1 o
o o 1
IMP
X Y X IMP Y
1 1 1
1 o o
o 1 1
o o 1
"AA"<"AB"
"FILENAME"="FILENAME"
"X&">"X#II
"CL ">"CL"
"kg">"KG"
"SMYTH" <" SMYTHE"
B$<"9/l2/78" where B$="8/12/78"
Thus, string comparisons can be used to test string values
or to alphabetize strings. All string constants used in
comparison expressions must be enclosed in quotation marks.
)
)
Chapter 2 Microsoft BASIC Commands and Statements
Introduction
2.1 AUTO
2.2 CALL
2.3 CHAIN
2.4 CLEAR
2.5 CLOAD
2.6 CLOSE
2.7 COMMON
2.8 CONT
2.9 CSAVE
2.10 DATA
2.11 DEF FN
2.12 DEFINT/SNG/DBL/STR
2.13 DEF USR
2.14 DELETE
2.15 DIM
2.16 EDIT
2.17 END
2.18 ERASE
2.19 ERR and ERL Variables
2.20 ERROR
2.21 FIELD
2.22 FOR ... NEXT
2.23 GET
2.24 GOSUB ••. RETURN
2.25 GOTO
2.26 IF .•. THEN[ ... ELSE] and IF •.. GOTO
) 2.27 INPUT
2.28 INPUT*
2.29 KILL
2.30 LET
2.31 LINE INPUT
2.32 LINE INPUT*
2.33 LIST
2.34 LLIST
2.35 LOAD
2.36 LPRINT and LPRINT USING
2.37 LSET and RSET
2.38 MERGE
2.39 MID$
2.40 NAME
2.41 NEW
2.42 NULL
2.43 ON ERROR GOTO
2.44 ON •.• GOSUB and ON ••. GOTO
2.45 OPEN
2.46 OPTION BASE
2.47 OUT
2.48 POKE
2.49 PRINT
2.50 PRINT USING
2.51 PRINT# and PRINT* USING
) 2.52 PUT
GENERAL INFORMATION ABOUT MICROSOFT BASIC
2.53 RANDOMIZE
2.54 READ
2.55 REM
2.56 RENUM
2.57 RESTORE
2.58 RESUME
2.59 RUN
2.60 SAVE
2.61 STOP
2.62 SWAP
2.63 TRON!TROFF
2.64 WAIT
2.65 WHILE .•. WEND
2.66 WIDTH
2.67 WRITE
2.68 WRITEi!
)
CHAPTER 2
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-2
2.1 AUTO
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-3
2.2 CALL
)
Note In a Microsoft BASIC Compiler program, line no
is not required because the address of MYROUT
will be assigned by the linking loader at load
time.
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-4
2.3 CHAIN
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-5
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-7
2.4 CLEAR
Examples CLEAR
CLEAR ,32768
CLEAR, ,2000
CLEAR ,32768,2000
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-8
2.5 CLOAD
)
MICROSOFT BASIC COMMANDS AND STAT~lENTS Page 2-9
2.6 CLOSE
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-10
2.7 COMMON
For example:
MENU.BAS
10 $INCLUDE COMDEF
PROGl.BAS
10 $INCLUDE COMDEF
COMDEF.BAS
100 DIM A(lOO) ,B$ (200)
) 110 COMMON I,J,K,A()
120 COMMON A$,B$(),X,Y,Z
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-12
2.8 CONT
Format CONT
Purpose To continue program execution after a Control-C
has been typed or a STOP or END statement has
been executed.
Remarks Execution resumes at the point where the break
occurred. If the break occurred after a prompt
from an INPUT statement, execution continues
with the repr in ting of the prompt ("?" or prompt
str ing) .
CONT is usually used in conjunction with STOP
for debugging. When execution is stopped,
intermediate values may be examined and changed
using direct mode statements. Execution may be
resumed with CONT or a direct mode GOTO, which
resumes execution at a specified line number.
CONT may be used to continue execution after an
error has occurred.
CONT is invalid if the program has been edited
dur ing the break.
Example See "STOP," Section 2.61. )
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-13
2.9 CSAVE
0,0
1,0
2,0
0,1
1,1
2,1
0,2
1,2
2,2
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-15
2.10 DATA
not needed.
The variable type (numeric or string) given in
the READ statement must agree with the
corresponding constant in the DATA statement.
DATA statements may be reread from the beginning
by use of the RESTORE statement (Section 2.57).
Example See "READ," Section 2.54.
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-16
2.11 DEF FN
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-17
Example
410 DEF FNAB(X,Y)=X~3/Y~2
420 T=FNAB(I,J)
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-18
2.12 DEFINT/SNG/DBL/STR
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-20
2.14 DELETE
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-21
2.15 DIM
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-22
2.16 EDIT
3. Deleting text.
4. Finding text.
S. Replacing text.
4. Finding Text
Control-A
To enter edit mode on the line you are currently
typing,
responds
type
with
Control-A.
a <carriage
Microsoft
return>,
BASIC
an
)
exclamation point (!), and a space. The cursor
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-25
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-26
2.17 END
Format END
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-27
2.18 ERASE
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-28
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-29
2.20 ERROR
Example 1 LIST
10 S=lO
20 T=5
30 ERROR S+T
40 END
Ok
RUN
String too long in line 30
Or, in direct mode:
Ok
ERROR 15 (You type this line.)
Str ing too long (BASIC types th is li ne. )
Ok
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-30
Example 2
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-31
2.21 FIELD
Example 3 10 I=5
20 FOR I=l TO I+5
30 PRINT I;
40 NEXT
RUN
1 2 3 4 5 6 7 8 9 10
Ok
In this example, the loop executes ten times.
The final value for the loop variable is always
set before the initial value is set.
2.23 GET
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-36
RETURN
Example 10 GOSUB 40
20 PRINT "BACK FROM SUBROUTINE"
30 END
40 PRINT "SUBROUTINE";
50 PRINT " IN";
60 PRINT" PROGRESS"
70 RETURN
RUN
SUBROUTINE IN PROGRESS
BACK FROM SUBROUTINE
Ok
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-37
2.25 GOTO
Example LIST
10 READ R
20 PRINT "R =" iR,
A
30 A=3.14*R 2
40 PRINT "AREA =" ;A
50 GOTO 10
60 DATA 5,7,12
Ok
RUN
R = 5 AREA = 78.5
R = 7 AREA = 153.86
R = 12 AREA = 452.16
) ?Out of data in 10
Ok
)
MIC~OSOFT BASIC COMMANDS AND STATEMENTS Page 2-38
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-39
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-40
2.27 INPUT
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-41
Examples 10 INPUT x
A
20 PRINT X "SQUARED IS" X 2
30 END
RUN
? 5 (The 5 was typed in by the user
in response to the question mark.)
5 SQUARED 'Is 25
Ok
LIST ,
10 PI=3.14
20 INPUT "WHAT IS THE RADIUS"; R
30 A=PI*R A 2
40 PRINT "THE AREA OF THE CIRCLE IS";A
50 PRINT
60 GOTO 20
Ok
RUN
WHAT IS THE RADIUS? 7.4 (User types 7.4)
THE AREA OF THE CIRCLE IS 171.946
)
MICROSOFT BASIC COMMANDS AND STATlliENTS Page 2-42
2.28 INPUTji
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-43
2.29 KILL
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-44
2.30 LET
or
110 D=12
120 E=12~2
A
130 F=12 4
140 SUM=D+E+F
)
)
MICROSOFT BASIC COMMANDS A..'<D STATEMENTS Page 2-45
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-46
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-47
2.33 LIST
Examples Format 1
Format 2
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-49
2.34 LLIST
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-50
2.35 LOAD
)
MICROSOFT BASIC COM..~ANDS AND STATEMENTS Page 2-51
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-52
)
MICROSOFT BASIC CO~~ANDS AND STATEMENTS Page 2-53
2.38 MERGE
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-54
2.39 MID$
2.40 NAME
Example Ok
NAME "ACCTS" AS "LEDGER"
Ok
In this example, the file that was
formerly named ACCTS will now be named LEDGER.
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-56
2.41 NE'il
Format NEW
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-57
2.42 NULL
).
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-58
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-60
2.45 OPEN
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-61
where n is 1 or 0
OPTION BASE 1
is executed, the lowest value an array subscript
may have is 1.
Example OPTION BASE 1
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-62
2.47 OUT
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-63
2.48 POKE
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-64
2.49 PRINT
Example 1 10 X=5
) 20 PRINT X+5,X-5,X*(-5),X 5
30 END
A
RUN
10 0 -25 3125
Ok
In this example, the commas in the PRINT
statement cause each value to be printed at the
beginning of the next print zone.
Example 2 LIST
10 INPUT X
A
20 PRINT X "SQUARED IS" X 2 "AND";
30 PRINT X "CUBED IS" XA 3
40 PRINT
50 GOTO 10
Ok
RUN
? 9
9 SQUARED IS 81 AND 9 CUBED IS 729
? 21
21 SQUARED IS 441 AND 21 CUBED IS 9261
?
) In this example, the semicolon at the end of
line 20 causes both PRINT statements to be
printed on the same line. Line 40 causes a
blank line to be printed before the next prompt .
•
Example 3 10 FOR X=l TO 5
20 J=J+5
30 K=K+IO
40 ?JiKi
50 NEXT X
Ok
RUN
5 10 10 20 15 30 20 40 25 50
Ok
In this example, the semicolons in the PRINT
sta temen t cause each value to be pr in ted
immediately after the preceding value. (Don't
forget, 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 of
the word PRINT.
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-66
Example:
10 A$="LOOK" :B$="OOT"
30 PRINT USING "!"; A$; B$
40 PRINT USING "\ \" ;A$;B$
50 PRINT USING "\ \";A$;B$;"!!"
RUN
LO
LOOKOUT
LOOK OUT !!
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-67
Example:
10 A$="LOOK" :B$="OOT"
20 PRINT USING "!"; A$;
30 PRINT USING "&" ;B$
RUN
LOUT
Numeric Fields
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-68
)
MICROSOFT BASIC COMM&~DS AND STATEMENTS Page 2-70
PRINT#l,A;B;C;X;Y;Z
(If commas are used as delimiters, the extra
blanks that are inserted between print fields
will also be written to the disk.)
variables.
If the strings themselves contain commas,
semicolons, significant leading blanks, carriage
returns, or line feeds, write them to disk
surrounded by explicit quotation marks,
CHR$ (34) •
For example, let A$="CAMERA, AUTOMATIC" and
B$=" 93604-1". The statement
PRINTU ,A$; B$
would write the following image to disk:
CAMERA, AUTOMATIC 93604-1
INPUTU ,A$,B$
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-72
2.52 PUT
)
MICROSOFT BASIC COMMANDS AND STATDIENTS Page 2-73
2.53 RANDOMIZE
Example 10 RANDOM I ZE
20 FOR I=l TO 5
30 PRINT RND;
40 NEXT I
) RUN
Random Number Seed (-32768 to 32767)? 3
(user types 3)
.88598 .484668 .586328 .119426 .709225
Ok
RUN
Random Number Seed (-32768 to 32767)? 4
(user types 4 for new sequence)
.803506 .162462 .929364 .292443 .322921
Ok
RUN
Random Number Seed (-32768 to 32767)? 3
(same sequence as first RUN)
.88598 .484668 .586328 .119426 .709225
Ok
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-74
2.54 READ
80 FOR I=l TO 10
90 READ A(I)
100 NEXT I
110 DA.TA 3.08,5.19,3.12,3.98,4.24
120 DATA 5.08,5.55,4.00,3.16,3.37
Example 2 LIST
10 PRINT "CITY", "STATE", " ZIP"
20 READ C$,S$,Z
30 DATA "DENVER,", COLORADO, 80211
40 PRINT C$,S$,Z
Ok
RUN
CITY STATE ZIP
DENVER, COLORADO 80211
Ok
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-76
2.55 REM
Example
or
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-77
2.56 RENUM
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-78
2.57 RESTORE
)
MICROSOFT BASIC COMMkNDS AND STATD1ENTS Page 2-79
2.58 RESUHE
Formats RESUME
RESUME 0
RESUME NEXT
RESUME <line number>
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-80
2.59 RUN
Purpose To load a file from disk into memory and run it.
Remarks <filename> is the name used when the file was
SAVEd. (Your opera ting ,system may append a
default filename extension if one was not
supplied in the SAVE command. Refer to
"Microsoft BASIC Disk I/O," in the Microsoft
BASIC User's Guide for information about
possible filename extensions 'under your
operating system.)
RUN closes all open files and deletes the
current contents of memory before loading the
designated program. However, with the "R"
option, all data files rema in OPEN.
Example RUN "NEWFIL",R
See also "Microsoft BASIC Disk I/O," in the
Microsoft BASIC User's Guide.
Note Microsoft BASIC Compiler supports the RUN and
RUN <line number> 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 Page 2-81
2.60 SAVE
I
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-82
2.61 STOP
Format STOP
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-83
2.62 SWAP
Example LIST
10 A$=" ONE " : B$=" ALL " C$=" FOR"
20 PRINT A$ C$ B$
30 SWAP A$, B$
40 PRINT A$ C$ B$
RUN
Ok
ONE FOR ALL
ALL FOR ONE
Ok
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-84
2.63 TRON/TROFF
Format TRON
TROFF
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-85
2.64 WAIT
)
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-86
[<loop statements>]
WEND
Purpose To execute a series of statements in a loop as
long as a given condition is true.
Remarks If <expression> is not zero (Le., true), <loop
statements> are executed until the WEND
statement is encountered. Microsoft BASIC then
returns to the WHILE statement and checks
<expression>. If it is still true, the process
is repeated. If it is not true, execution
resumes with the statement following the WEND
statemen t.
WHILE/WEND loops may be nested to any level.
Each WEND will match the most recent WHILE. An
unmatched WHILE statement causes a "WHILE
without WEND" error, and an unmatched WEND
statement causes a "WEND without WHILE" error.
Exa'llple 90 'BUBBLE SORT ARRAY A$
100 FLIPS=l 'FORCE ONE PASS THRU LOOP
110 WHILE FLIPS
115 FLIPS=O
120 FOR I=l TO J-l
130 IF A$(I»A$(I+l) THEN
SWAP A$(I),A$(I+l) :FLIPS=l
140 NEXT I
150 WEND
MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-87
2.66 WIDTH
)
MICROSOFT BASIC CO~~ANDS AND STATEMENTS Page 2-88
2.67 WRITE
2 .68 WRITE?,
The statement:
WRITE#! ,A$ ,B$
)
writes the following image to disk:
"CAMERA", "93604-1"
)
)
Chapter 3 Microsoft BASIC Functions
Introduction
3.1 ABS
3.2 ASC
3.3 ATN
3.4 CDBL
3.5 CHR$
3.6 CINT
3.7 COS
3.8 CSNG
3.9 CVI, CVS, CVD
3.10 EOF
3.11 EXP
3.12 FIX
3.13 FRE
3.14 HEX$
3.15 INKEY$
3.16 INP
3.17 INPUT$
3.18 INSTR
3.19 INT
3.20 LEFT$
3.21 LEN
3.22 LOC
3.23 LOG
3.24 LPOS
3.25 MID$
3.26 MIK$, MKS$, MKD$
) 3.27 OCT$
3.28 PEEK
3.29 POS
3.30 RIGHT$
3.31 RND
3.32 . SGN
3.33 SIN
3.34 SPACES
3.35 SPC
3.36 SQR
3.37 STR$
3.38 STRING$
3.39 TAB
3.40 TAN
3.41 USR
3.42 VAL
3.43 VARPTR
)
)
CHAPTER 3
MICROSOFT BASIC FUNCTIONS
)
MICROSOFT BASIC FUNCTIONS Page 3-2
3.1 ABS
Format ABS(X)
3.2 ASC
Format ASC(X$)
Action Returns a numerical value that is the ASCII code
for the first character of the string X$. (See
Appendix C for ASCII codes.) If X$ is null, an
"Illegal function call" error is returned.
Example 10 X$="TEST"
20 PRINT ASC (X$)
RUN
84
Ok
3.3 ATN
3.4 CDBL
Example 10 A=454.67
) 20 PRINT A;CDBL (A)
RUN
454.67 454.6700134277344
Ok
/
MICROSOFT BASIC FUNCTIONS Page 3-4
3.5 CHR$
Format CHR$(I)
Action Returns a string whose one character is ASCII
character I. (ASCII codes are listea in
Appendix C.) CHR$ is commonly used to send a
special character to the terminal. For
instance, the BEL character (CHR$(7)) could be
sent as a preface to an error message, or a form
feed (CHR$(12» could be sent to clear a
terminal screen and return the cursor to the
home position.
Example PRINT CHR$ (66)
B
Ok
3.6 CINT
)
MICROSOFT BASIC FUNCTIONS Page 3-5
3.7 COS
3.8 CSNG
Example 10 Ai = 975.3421#
20 PRINT A#: CSNG(A#)
RUN
) 975.3421 975.341
Ok
)
MICROSOFT BASIC FUNCTIONS Page 3-6
-Example
3.10 EOF
)
MICROSOFT BASIC FUNCTIONS Page 3-7
3.11 EXP
Format EXP(X)
Action Returns e (base of natural logarithms) to the
power of X. X must be <=87.3365. If EXP
overflows, the "Overflow" error message is
displayed, machine infinity with the appropriate
sign is supplied as the result, and execution
continues.
Example 10 X=5
20 PRINT EXP(X-l)
RUN
54.5982
Ok
3.12 FIX
PRINT FIX(-58.75)
-58
Ok
)
MICROSOFT BASIC FUNCTIONS Page 3-8
3.13 FRE
Format FRE(O)
FRE(UU)
3.14 HEX$
Format HEX$(X)
3.15 INKEY$
Format INKEY$
3.16 INP
)
Format INP (I)
)
MICROSOFT BASIC FUNCTIONS Page 3-10
3.17 INPUT$
Format INPUT$(X[,[#]Y])
Example 2
)
MICROSOFT BASIC FUNCTIONS Page 3-11
3.18 INSTR
Example 10 X$="ABCDEB"
20 Y$="B"
30 PRINT INSTR(X$,Y$) ;INSTR(4,X$,Y$)
RUN
2 6
Ok
)
MICROSOFT BASIC FUNCTIONS Page 3-12
3.19 INT
PRINT INT(-12.11)
-13
Ok
3.20 LEFT$
Format LEFT$(X$,I)
)
MICROSOFT BASIC FUNCTIONS Page 3-13
3.21 LEN
3.22 LOC
)
MICROSOFT BASIC FUNCTIONS Page 3-14
3.23 LOG
3.24 LPOS
Format LPOS(X)
Action Returns the current position of the line printer
print head within the line printer's buffer.
Does not necessarily give the physical position
of the print head. X is a dummy argument.
Example 100 IF LPOS(X»60 THEN LPRINT CHR$(13)
)
MICROSOFT BASIC FUNCTIONS Page 3-15
3.25 MID$
Format MID$(X$,I[,J))
Example LIST
10 A$="GOOD "
20 B$="MORNING EVENING AFTERNOON"
30 PRINT A$;MID$(B$,9,7)
Ok
RUN
GOOD EVEN ING
Ok
)
MICROSOFT BASIC FUNCTIONS Page 3-16
3.27 OCT$
Format OCT$(X}
3.28 PEEK
Format PEEK(I}
.J
MICROSOFT BASIC FUNCTIONS Page 3-18
3.29 POS
Format POS(I)
3.30 RIGHT$
Format RIGHT$(X$,I)
)
MICROSOFT BASIC FUNCTIONS Page 3-19
3.31 RND
)
MICROSOFT BASIC FUNCTIONS Page 3- 20
3.33 SIN
3.34 SPACE$
Format SPACE$(X)
)
MICROSOFT BASIC FUNCTIONS Page 3-21
3.35 SPC
Format SPC(I)
3.36 SQR
Format SQR(X)
)
MICROSOFT BASIC FUNCTIONS Page 3-22
3.37 STR$
Format STR$(X)
3.38 STRING$
3.39 TAB
Format TAB(Il
Action Spaces to position I on the terminal. If the
current print position is already beyond space
I, TAB goes to that position on the next line.
Space 1 is the leftmost position, and the
rightmost position is the width minus one. I
must be in the range 1 to 255. TAB may only be
used in PRINT and LPRINT statements.
Example 10 PRINT "NAJ1E" TAB (25 1 "AMOUNT" : PRINT
20 READ A$ ,B$
30 PRINT A$ TAB(25l B$
40 DATA "G. T. JONES", "$25 .00"
RUN
NAME AMOUNT
G. T. JONES $25.00
Ok
3.40 TAN
)
Format TAN (X)
)
MICROSOFT BASIC FUNCTIONS Page 3-24
3.41 USR
3.42 VAL
Format VAL(X$)
returns -3.
Example 10 READ NAME$,CITY$,STATE$,ZIP$
20 IF VAL(ZIP$)<90000 OR VAL(ZIP$»96699
THEN PRINT NAME$ TAB(25) "OUT OF STATE"
30 IF VAL(ZIP$»=90801 AND VAL(ZIP$)<=90815
THEN PRINT NAME$ TAB (25) "LONG BEACH"
)
MICROSOFT BASIC FUNCTIONS Page 3-25
3.43 VARPTR
Action Format 1
Format 2
)
)
)
MICROSOFT BASIC FUNCTIONS
Appendices
)
)
)
APPENDIX A
SN 2 Syntax error
A line is encountered that contains some
incorrect sequence of characters (such as
) unmatched parenthesis, misspelled command or
statement, incorrect punctuation, etc.).
Microsoft BASIC automatically enters edit
mode at the line that caused the error.
00 4 Out of data
OM 7 Out of memory
DD 10 Redimensioned array
/0 11 Division by zero
TM 13 Type mismatch
CN 17 Can't continue
19 No RESUME
) An error handling routine is entered but
contains no RESUME statement.
Page A-4
21 Unprintable error
22 Missing operand
An expression contains an operator with no
operand following it.
23 Line buffer overflow
An attempt has been made to input a line that
has too many characters.
26 FOR without NEXT
Disk Errors
50 Field overflow
initialization.
)
Page A-6
)
APPENDIX B
Mathematical Functions
Derived Functions
)
APPENDIX C
)
APPENDIX D
MICROSOFT BASIC RESERVED WORDS
)
)
)
INDEX
ABS 3-2
Addition 1-10
ALL 2-4, 2-10
Arctangent 3-3
Array variables 1-7, 2-10, 2-21
Arrays
· · · 1-7, 2-8, 2-13, 2-27
ASC
····
ASCII codes
3-2
3-2, 3-4
ASCII format 2-5, 2-53, 2-81
Assembly language subroutines 2-3, 2-19, 2-63, 3-24 to 3-25
ATN
· · · · · · .. 3-3
AUTO
· ····· 1-2, 2-2
CALL
······
Carriage return
2-3
1-3, 2-40, 2-45 to 2-46,
2-87 to 2-89
Cassette tape 2-8, 2-13
CDBL
· · ·· ·· · 3-3
)
CHAIN
Character set · 2-4,
1-3
2-10
CHR$
· 3-4
CINT
·
CLE.l>,R
3-4
2-7
CLOAD 2-8
CLOAD* 2-8
CLOAD? 2-8
CLOSE 2-9
Command level 1-1
COMMON
· · · ·
Concatenation
2-4,
1-16
2-10
Constants 1-4
CONT
·····
Control characters
2-12,
1-4
2-45
Control-A 2-24
COS 3-5
CSAVE 2-13
CSAVE* 2-13
CSNG 3- 5
CVD 3-6
CVI 3-6
CVS 3-6
FIELD 2-31
FIX 3-7
FOR ... NEXT 2-33 )
FRE . . . 3-8
Functions 1-15, 2-16, 3-1, B-1
HEX$ 3-8
Hexadecimal 1-5, 3-8
KILL . • 2-43
LEFT$ 3-12
LEN 3-13
LET 2-31, 2-44
Line feed 1-2, 2-40, 2-45 to 2-46,
2-88 to 2-89
LINE INPUT 2-45
LINE INPUT# 2-46
Line numbers 1-1 to 1-2, 2-2, 2-77
Line printer 2-49, 2-51, 2-87, 3-14
Lines 1-1
LIST • 1-2, 2-47
LLIST 2-49
LOAD 2-50, 2-81
LOC 3-13
LOG 3-14
Logical operators 1-13
Loops 2-33, 2-86
LPOS . • • • 2-87, 3-14
LPRINT . • • 2-51, 2-87
LPRINT USING 2-51
LSET • 2-52
OCT$ • • • • • 3-17
Oc tal • • • • 1-5,3-17
ON ERROR GOTO 2-58
ON •.. GOSUB 2-59
ON ... GOTO 2-59
OPEN . • • 2-9, 2-31, 2-60
Operator s 1-10, 1-12 to 1-13, 1-15 to 1-16
OPTION BASE 2-61
OUT 2-62
Overflow 1-12, 3-7, 3-23
Overlay 2-4
TAB 3-23
Tab 1-3 to 1-4
TAN 3-23
TROFF 2-84
TRON 2-84
VAL 3-24 )
Variables 1-6
VARPTR 3-25
WAIT . 2-85
WEND. 2-86
WHILE 2-86
WIDTH 2-87
WIDTH LPRINT 2-87
WRITE . 2-88
WRITE# . • • 2-89