ChipMaster's bwBASIC This also includes history going back to v2.10. *WARN* some binary files might have been corrupted by CRLF.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

6445 lines
189 KiB

  1. FILENAME: BASIC-80.txt
  2. ORIGINAL: http://chiclassiccomp.org/docs/content/computing/Microsoft/Microsoft_Basic_8086Xenix_Reference.pdf
  3. SPLIT PDF: http://www.splitpdf.com/
  4. OCR PDF: http://www.onlineocr.net/
  5. TOTAL PAGES: 167
  6. Microsoft(TM) BASIC
  7. Reference Manual
  8. Microsoft Corporation
  9. Information in this document is subject to change without
  10. notice and does not represent a commitment on the part of
  11. Microsoft Corporation. The software described in this
  12. document is furnished under a license agreement or
  13. non-disclosure agreement. The software may be used or
  14. copied only in accordance with the terms of the agreement.
  15. It is against the law to copy Microsoft(TM) BASIC on
  16. magnetic tape, disk, or any other medium for any purpose
  17. other than the purchaser's personal use.
  18. (C) Microsoft Corporation 1979, 1982
  19. Microsoft Corporation
  20. Microsoft Building
  21. 10700 Northup Way
  22. C-97200
  23. Bellevue, Washington 98004
  24. CP/M is a registered trademark of Digital Research, Inc.
  25. Microsoft, Microsoft BASIC Interpreter, Microsoft BASIC
  26. Compiler, Microsoft FORTRAN Compiler, and Microsoft COBOL
  27. Compiler are trademarks of Microsoft Corporation.
  28. Teletype is a registered trademark of Teletype Corporation.
  29. Document no. 8101-530-11
  30. Part no. 00F14RM
  31. Contents
  32. Introduction
  33. Chapters 1 General Information about Microsoft BASIC
  34. 1.1 Initialization
  35. 1.2 Modes of Operation
  36. 1.3 Line Format
  37. 1.4 Character Set
  38. 1.5 Constants
  39. 1.6 Variables
  40. 1.7 Type Conversion
  41. 1.8 Expressions and Operators
  42. 1.9 Input Editing
  43. 1.10 Error Messages
  44. 2 Microsoft BASIC Commands and Statements
  45. 2,1 AUTO
  46. 2.2 CALL
  47. 2.3 CHAIN
  48. 2.4 CLEAR
  49. 2.5 CLOAD
  50. 2.6 CLOSE
  51. 2.7 COMMON
  52. 2.8 CONT
  53. 2.9 CSAVE
  54. 2.10 DATA
  55. 2.11 DEF FN
  56. 2.12 DEFINT/SNG/DBL/STR
  57. 2.13 DEF USR
  58. 2.14 DELETE
  59. 2.15 DIM
  60. 2.16 EDIT
  61. 2.17 END
  62. 2.18 ERASE
  63. 2.19 ERR and ERL Variables
  64. 2.20 ERROR
  65. 2.21 FIELD
  66. 2.22 FOR...NEXT
  67. 2.23 GET
  68. 2.24 GOSUB...RETURN
  69. 2.25 GOTO
  70. 2.26 IF...THEN[...ELSE] and IF...GOTO
  71. 2.27 INPUT
  72. 2.28 INPUT#
  73. 2.29 KILL
  74. 2.30 LET
  75. 2.31 LINE INPUT
  76. 2.32 LINE INPUT#
  77. 2.33 LIST
  78. 2.34 LLIST
  79. 2.35 LOAD
  80. 2.36 LPRINT and LPRINT USING
  81. 2.37 LSET and RSET
  82. 2.38 MERGE
  83. 2.39 MID$
  84. 2.40 NAME
  85. 2.41 NEW
  86. 2.42 NULL
  87. 2.43 ON ERROR GOTO
  88. 2.44 ON...GOSUB and ON...GOTO
  89. 2.45 OPEN
  90. 2.46 OPTION BASE
  91. 2.47 OUT
  92. 2.48 POKE
  93. 2.49 PRINT
  94. 2.50 PRINT USING
  95. 2.51 PRINT# and PRINT# USING
  96. 2.52 PUT
  97. 2.53 RANDOMIZE
  98. 2.54 READ
  99. 2.55 REM
  100. 2.56 RENUM
  101. 2.57 RESTORE
  102. 2.58 RESUME
  103. 2.59 RUN
  104. 2.60 SAVE
  105. 2.61 STOP
  106. 2.62 SWAP
  107. 2.63 TRON/TROFF
  108. 2.64 WAIT
  109. 2.65 WHILE...WEND
  110. 2.66 WIDTH
  111. 2.67 WRITE
  112. 2.68 WRITE#
  113. 3 Microsoft BASIC Functions
  114. 3.1 ABS
  115. 3.2 ASC
  116. 3.3 ATN
  117. 3.4 CDBL
  118. 3.5 CHR$
  119. 3.6 CINT
  120. 3.7 COS
  121. 3.8 CSNG
  122. 3.9 CVI, CVS, CVD
  123. 3.10 EOF
  124. 3.11 EXP
  125. 3.12 FIX
  126. 3.13 FRE
  127. 3.14 HEX$
  128. 3.15 INKEY$
  129. 3.16 INP
  130. 3.17 INPUT$
  131. 3.18 INSTR
  132. 3.19 INT
  133. 3.20 LEFT$
  134. 3.21 LEN
  135. 3.22 LOC
  136. 3.23 LOG
  137. 3.24 LPOS
  138. 3.25 MID$
  139. 3.26 MIK$, MKS$, MKD$
  140. 3.27 OCT$
  141. 3.28 PEEK
  142. 3.29 POS
  143. 3.30 RIGHT$
  144. 3.31 RND
  145. 3.32 SGN
  146. 3.33 SIN
  147. 3.34 SPACE$
  148. 3.35 SPC
  149. 3.36 SQR
  150. 3.37 STR$
  151. 3.38 STRING$
  152. 3.39 TAB
  153. 3.40 TAN
  154. 3.41 USR
  155. 3.42 VAL
  156. 3.43 VARPTR
  157. Appendices A Error Codes and Error Messages
  158. B Mathematical Functions
  159. C ASCII Character Codes
  160. D Microsoft BASIC Reserved Words
  161. Index
  162. <<< blank page >>>
  163. Introduction
  164. Microsoft(TM) BASIC is the most extensive implementation of
  165. BASIC available for microprocessors. Microsoft BASIC meets
  166. the ANSI qualifications for BASIC, as set forth in document
  167. BSRX3.60-1978. Each release of Microsoft BASIC is
  168. compatible with previous versions.
  169. How to Use this Manual
  170. This manual is a reference for all implementations of
  171. Microsoft BASIC and for the Microsoft(TM) BASIC Compilers.
  172. The manual is divided into three chapters plus three
  173. appendices. Chapter 1 covers a variety of topics, largely
  174. pertaining to data representation in Microsoft BASIC.
  175. Chapter 2 describes the syntax and semantics of every
  176. command and statement in Microsoft BASIC, ordered
  177. alphabetically. Chapter 3 describes all Microsoft BASIC
  178. intrinsic functions, also ordered alphabetically. The
  179. appendices contain a list of error messages and codes, a
  180. list of mathematical functions, and a list of ASCII
  181. character codes.
  182. Additional information about programming Microsoft BASIC is
  183. covered in the Microsoft BASIC User's Guide. The User's
  184. Guide describes the features of Microsoft BASIC that are
  185. implemented for your machine. It also contains information
  186. relevant to your operating system and helpful hints about
  187. such matters as data I/O and assembly language subroutines.
  188. Syntax Notation
  189. Wherever the format for a statement or command is given, the
  190. following rules apply:
  191. CAPS Items in capital letters must be input as shown.
  192. < > Items in lower case letters enclosed in angle
  193. brackets (< >) are to be supplied by the user.
  194. [ ] Items in square brackets ([ ]) are optional.
  195. ... Items followed by an ellipsis (...) may be repeated
  196. any number of times (up to the length of the line).
  197. { } Braces indicate that the user has a choice between
  198. two or more entries. At least one of the entries
  199. enclosed in braces must be chosen unless the entries
  200. are also enclosed in square brackets.
  201. | Vertical bars separate the choices within braces. At
  202. least one of the entries separated by bars must be
  203. chosen unless the entries are also enclosed in square
  204. brackets.
  205. All punctuation except angle brackets and square
  206. brackets (i.e., commas, parentheses, semicolons,
  207. hyphens, equal signs) must be included where shown.
  208. Chapter 1 General Information about Microsoft BASIC
  209. 1.1 Initialization
  210. 1.2 Modes of Operation
  211. 1.3 Line Format
  212. 1.3.1 Line Numbers
  213. 1.4 Character Set
  214. 1.4.1 Control Characters
  215. 1.5 Constants
  216. 1.5.1 Single and Double Precision Form
  217. for Numeric Constants
  218. 1.6 Variables
  219. 1.6.1 Variable Names and Declaration Characters
  220. 1.6.2 Array Variables
  221. 1.6.3 Space Requirements
  222. 1.7 Type Conversion
  223. 1.8 Expressions and Operators
  224. 1.8.1 Arithmetic Operators
  225. 1.8.1.1 Integer Division and Modulus Arithmetic
  226. 1.8.1.2 Overflow and Division by Zero
  227. 1.8.2 Relational Operators
  228. 1.8.3 Logical Operators
  229. 1.8.4 Functional Operators
  230. 1.8.5 String Operators
  231. 1.9 Input Editing
  232. 1.10 Error Messages
  233. <<< blank page >>>
  234. CHAPTER 1
  235. GENERAL INFORMATION ABOUT MICROSOFT BASIC
  236. 1.1 INITIALIZATION
  237. The procedure for initialization will vary with different
  238. implementations of Microsoft BASIC. Check the Microsoft
  239. BASIC User's Guide for your machine to determine how
  240. Microsoft BASIC is initialized with your operating system.
  241. 1.2 MODES OF OPERATION
  242. When Microsoft BASIC is initialized, it displays the prompt
  243. "Ok". "Ok" indicates Microsoft BASIC is at command level;
  244. that is, it is ready to accept commands. At this point,
  245. Microsoft BASIC may be used in either of two modes: direct
  246. mode or indirect mode.
  247. In direct mode, Microsoft BASIC statements and commands are
  248. not preceded by line numbers. They are executed as they are
  249. entered. Results of arithmetic and logical operations may
  250. be displayed immediately and stored for later use, but the
  251. instructions themselves are lost after execution. Direct
  252. mode is useful for debugging and for using Microsoft BASIC
  253. as a "calculator" for quick computations that do not require
  254. a complete program.
  255. Indirect mode is used for entering programs. Program lines
  256. are preceded by line numbers and are stored in memory. The
  257. program stored in memory is executed by entering the RUN
  258. command.
  259. 1.3 LINE FORMAT
  260. Microsoft BASIC program lines have the following format
  261. (square brackets indicate optional input)
  262. nnnnn BASIC statement[:BASIC statement...] <carriage return>
  263. GENERAL INFORMATION ABOUT MICROSOFT BASIC Page l-2
  264. More than one BASIC statement may be placed on a line, but
  265. each must be separated from the last by a colon.
  266. A Microsoft BASIC program line always begins with a line
  267. number and ends with a carriage return. A line may contain
  268. a maximum of 255 characters.
  269. It is possible to extend a logical line over more than one
  270. physical line by using the <line feed> key. <line feed>
  271. lets you continue typing a logical line on the next physical
  272. line without entering a <carriage return>.
  273. 1.3.1 Line Numbers
  274. Every Microsoft BASIC program line begins with a line
  275. number. Line numbers indicate the order in which the
  276. program lines are stored in memory. Line numbers are also
  277. used as references in branching and editing. Line numbers
  278. must be in the range 0 to 65529.
  279. A period (.) may be used in EDIT, LIST, AUTO, and DELETE
  280. commands to refer to the current line.
  281. GENERAL INFORMATION ABOUT MICROSOFT BASIC Page 1-3
  282. 1.4 CHARACTER SET
  283. The Microsoft BASIC character set consists of alphabetic
  284. characters, numeric characters, and special characters.
  285. The alphabetic characters in Microsoft BASIC are the upper
  286. case and lower case letters of the alphabet.
  287. The Microsoft BASIC numeric characters are the digits 0
  288. through 9.
  289. In addition, the following special characters and terminal
  290. keys are recognized by Microsoft BASIC:
  291. Character Action
  292. Blank
  293. = Equals sign or assignment symbol
  294. + Plus sign
  295. - Minus sign
  296. * Asterisk or multiplication symbol
  297. / Slash or division symbol
  298. ^ Up arrow or exponentiation symbol
  299. ( Left parenthesis
  300. ) Right parenthesis
  301. % Percent
  302. # Number (or pound) sign
  303. $ Dollar sign
  304. ! Exclamation point
  305. [ Left bracket
  306. ] Right bracket
  307. , Comma
  308. . Period or decimal point
  309. ' Single quotation mark (apostrophe)
  310. ; Semicolon
  311. : Colon
  312. & Ampersand
  313. ? Question mark
  314. < Less than
  315. > Greater than
  316. \ Backslash or integer division symbol
  317. @ At sign
  318. _ Underscore
  319. <rubouE> Deletes last character typed.
  320. <escape> Escapes edit mode subcommands.
  321. See Section 2.16.
  322. <tab> Moves print position to next tab stop.
  323. Tab stops are set every eight columns.
  324. <line feed> Moves to next physical line.
  325. <carriage
  326. return> Terminates input of a line.
  327. GENERAL INFORMATION ABOUT MICROSOFT BASIC Page 1-4
  328. 1.4.1 Control Characters
  329. Microsoft BASIC supports the following control characters:
  330. Control Character Action
  331. Control-A Enters edit mode on the line being typed.
  332. Control-C Interrupts program execution and returns
  333. to BASIC command level.
  334. Control-G Rings the bell at the terminal.
  335. Control-H Backspaces. Deletes the last character
  336. typed.
  337. Control-I Tabs to the next tab stop. Tab stops are
  338. set every eight columns.
  339. Control-0 Halts program output while execution
  340. continues. A second Control-0 resumes
  341. output.
  342. Control-R Lists the line that is currently being
  343. typed.
  344. Control-S Suspends program execution.
  345. Control-Q Resumes program execution after a
  346. Control-S.
  347. Control-U Deletes the line that is currently being
  348. typed.
  349. 1.5 CONSTANTS
  350. Constants are the values Microsoft BASIC uses during
  351. execution. There are two types of constants: string and
  352. numeric.
  353. A string constant is a sequence of up to 255 alphanumeric
  354. characters enclosed in double quotation marks.
  355. Examples:
  356. "HELLO'
  357. "$25,000.00"
  358. "Number of Employees"
  359. Numeric constants are positive or negative numbers.
  360. Microsoft BASIC numeric constants cannot contain commas.
  361. There are five types of numeric constants:
  362. GENERAL INFORMATION ABOUT MICROSOFT BASIC Page 1-5
  363. 1.. Integer constants Whole numbers between -32768 and
  364. 32767. Integer constants do not
  365. contain decimal points.
  366. 2. Fixed-point Positive or negative real numbers,
  367. constants i.e., numbers that contain decimal
  368. points.
  369. 3. Floating-point Positive or negative numbers repre-
  370. constants sented in exponential form (similar
  371. to scientific notation). A
  372. floating-point constant consists of
  373. an optionally signed integer or
  374. fixed-point number (the mantissa)
  375. followed by the letter E and an
  376. optionally signed integer (the
  377. exponent). The allowable range for
  378. floating-point constants is 10-38
  379. to 10+38.
  380. Examples:
  381. 235.988E-7 = .0000235988
  382. 2359E6 = 2359000000
  383. (Double precision floating-point
  384. constants are denoted by the letter
  385. D instead of E. See Section
  386. 1.5.1.)
  387. 4. Hex constants Hexadecimal numbers, denoted by the
  388. prefix &H.
  389. Examples:
  390. &H76
  391. &H32F
  392. 5. Octal constants Octal numbers, denoted by the
  393. prefix &O or &.
  394. Examples:
  395. &O347
  396. &1234
  397. Note The 8K version of Microsoft BASIC does not support
  398. hexadecimal or octal constants.
  399. GENERAL INFORMATION ABOUT MICROSOFT BASIC Page 1-6
  400. 1.5.1 Single And Double Precision Form For Numeric Constants
  401. Numeric constants may be either single precision or double
  402. precision numbers. Single precision numeric constants are
  403. stored with 7 digits of precision, and printed with up to 6
  404. digits of precision. Double precision numeric constants are
  405. stored with 16 digits of precision and printed with up to 16
  406. digits.
  407. A single precision constant is any numeric constant that has
  408. one of the following characteristics:
  409. 1, Seven or fewer digits.
  410. 2. Exponential form using E.
  411. 3. A trailing exclamation point (!).
  412. Examples:
  413. 46.8
  414. -1.09E-06
  415. 3489.0
  416. 22.5!
  417. A double precision constant is any numeric constant that has
  418. one of these characteristics:
  419. 1. Eight or more digits.
  420. 2. Exponential form using D.
  421. 3. A trailing number sign (#).
  422. Examples:
  423. 345692811
  424. -1,09432D-06
  425. 3489.0*
  426. 7654321.1234
  427. 1.6 VARIABLES
  428. Variables are names used to represent values used in a BASIC
  429. program. The value of a variable may be assigned explicitly
  430. by the programmer, or it may be assigned as the result of
  431. calculations in the program. Before a variable is assigned
  432. a value, its value is assumed to be zero.
  433. GENERAL INFORMATION ABOUT MICROSOFT BASIC Page 1-7
  434. 1.6.1 Variable Names And Declaration Characters
  435. Microsoft BASIC variable names may be any length. Up to 40
  436. characters are significant. Variable names can contain
  437. letters, numbers, and the decimal point. However, the first
  438. character must be a letter. Special type declaration
  439. characters are also allowed--see below.
  440. A variable name may not be a reserved word, but embedded
  441. reserved words are allowed. Reserved words include all
  442. Microsoft BASIC commands, statements, function names, and
  443. operator names. If a variable begins with FN, it is assumed
  444. to be a call to a user-defined function.
  445. Variables may represent either a numeric value or a string.
  446. String variable names are written with a dollar sign ($) as
  447. the last character. For example: A$ = "SALES REPORT". The
  448. dollar sign is a variable type declaration character; that
  449. is, it "declares" that the variable will represent a string.
  450. Numeric variable names may declare integer, single
  451. precision, or double precision values. The type declaration
  452. characters for these variable names are as follows:
  453. % Integer variable
  454. ! Single precision variable
  455. # Double precision variable
  456. The default type for a numeric variable name is single
  457. precision.
  458. Examples of Microsoft BASIC variable names:
  459. PI# Declares a double precision value.
  460. MINIMUM! Declares a single precision value.
  461. LIMIT% Declares an integer value.
  462. N$ Declares a string value.
  463. ABC Represents a single precision value.
  464. There is a second method by which variable types may be
  465. declared. The Microsoft BASIC statements DEFINT, DEFSTR,
  466. DEFSNG, and DEFDBL may be included in a program to declare
  467. the types for certain variable names. These statements are
  468. described in detail in Section 2.12.
  469. 1.6.2 Array Variables
  470. An array is a group or table of values referenced by the
  471. same variable name. Each element in an array is referenced
  472. by an array variable that is subscripted with an integer or
  473. an integer expression. An array variable name has as many
  474. GENERAL rNFORmATION ABOUT MICROSOFT BASIC Page 1-8
  475. subscripts as there are dimensions in the array. For
  476. example V(10) would reference a value in a one-dimension
  477. array, T(1,4) would reference a value in a two-dimension
  478. array, and so on. The maximum number of dimensions for an
  479. array is 255. The maximum number of elements per dimension
  480. is 32,767.
  481. 1.6.3 Space Requirements
  482. The following table lists only the number of bytes occupied
  483. by the values represented by the variable names. Additional
  484. requirements may vary according to implementation.
  485. Variables Type Bytes
  486. Integer 2
  487. Single Precision 4
  488. Double Precision 8
  489. Arrays Type Bytes
  490. Integer 2 per element
  491. Single Precision 4 per element
  492. Double Precision 8 per element
  493. Strings
  494. 3 bytes overhead plus the present contents of the string.
  495. 1.7 TYPE CONVERSION
  496. When necessary, Microsoft BASIC will convert a numeric
  497. constant from one type to another. The following rules and
  498. examples should be kept in mind.
  499. 1. If a numeric constant of one type is set equal to a
  500. numeric variable of a different type, the number
  501. will be stored as the type declared in the variable
  502. name. (If a string variable is set equal to a
  503. numeric value or vice versa, a "Type mismatch"
  504. error occurs.)
  505. Example:
  506. 10 A%=23.42
  507. 20 PRINT A%
  508. RUN
  509. 23
  510. GENERAL INFORMATION ABOUT MICROSOFT BASIC Page 1-9
  511. 2. During expression evaluation, all of the operands
  512. in an arithmetic or relational operation are
  513. converted to the same degree of precision, i.e.,
  514. that of the most precise operand. Also, the result
  515. of an arithmetic a operation is returned to this
  516. degree of precision.
  517. Examples:
  518. 10 D#7=6*/7 The arithmetic was performed
  519. 20 PRINT D# in double precision and the
  520. RUN result was returned in D#
  521. .8571428571428571 as a double precision
  522. value.
  523. 10 D=6#/7 The arithmetic was performed
  524. 20 PRINT D in double precision and the
  525. RUN result was returned to D (single
  526. .857143 precision variable), rounded, and
  527. printed as a single precision
  528. value.
  529. 3. Logical operators (see Section 1.8.3) convert their
  530. operands to integers and return an integer result.
  531. Operands must be in the range -32768 to 32767 or an
  532. "Overflow" error occurs.
  533. 4. when a floating-point value is converted to an
  534. integer, the fractional portion is rounded.
  535. Example:
  536. 10 C%=55.88
  537. 20 PRINT C%
  538. RUN
  539. 56
  540. 5. If a double precision variable is assigned a single
  541. precision value, only the first seven digits
  542. (rounded) of the converted number will be valid.
  543. This is because only seven digits of accuracy were
  544. supplied with the single precision value. The
  545. absolute value of the difference between the
  546. printed double precision number and the original
  547. single precision value will be less than 6.3E-8
  548. times the original single precision value.
  549. Example:
  550. 10 A=2.04
  551. 20 B#=A
  552. 30 PRINT A; B#
  553. RUN
  554. 2.04 2.039999961853027
  555. GENERAL INFORMATION ABOUT MICROSOFT BASIC Page 1-10
  556. 1.8 EXPRESSIONS AND OPERATORS
  557. An expression may be a string or numeric constant, a
  558. variable, or a combination of constants and variables with
  559. operators which produces a single value.
  560. Operators perform mathematical or logical operations on
  561. values. The Microsoft BASIC operators may be divided into
  562. four categories:
  563. 1. Arithmetic
  564. 2. Relational
  565. 3. Logical
  566. 4. Functional
  567. Each category is described in the following sections.
  568. 1.8.1 Arithmetic Operators
  569. The arithmetic operators, in order of precedence, are:
  570. Operator Operation Sample Expression
  571. ^ Exponentiation X"Y
  572. - Negation -X
  573. *,/ Multiplication, Floating- X*Y
  574. point Division X/Y
  575. +,- Addition, Subtraction X+Y
  576. To change the order in which the operations are performed,
  577. use parentheses. Operations within parentheses are
  578. performed first. Inside parentheses, the usual order of
  579. operations is maintained.
  580. GENERAL INFORMATION ABOUT MICROSOFT BASIC Page 1-11
  581. Here are some sample algebraic expressions and their
  582. Microsoft BASIC counterparts.
  583. Algebraic Expression BASIC Expression
  584. X+2Y X+Y*2
  585. X- X-Y/Z
  586. X*Y/Z
  587. (X+Y)/Z
  588. (X (X^2)^Y
  589. X X^(Y^Z)
  590. X(-Y) X*(-Y) Two consecutive
  591. operators must
  592. be separated by
  593. parentheses.
  594. 1.8.1.1 Integer Division And Modulus Arithmetic -
  595. Two additional operators are available in Microsoft BASIC:
  596. integer division and modulus arithmetic.
  597. Integer division is denoted by the backslash (\). The
  598. operands are rounded to integers (must be in the range
  599. -32768 to 32767) before the division is performed, and the
  600. quotient is truncated to an integer.
  601. Example:
  602. 10\4=2
  603. 25.68\6.99=3
  604. Integer division follows multiplication and floating-point
  605. division in order of Precedence.
  606. Modulus arithmetic is denoted by the operator MOD. Modulus
  607. arithmetic yields the integer value that is the remainder of
  608. an integer division.
  609. Example:
  610. 10.4 MOD 4=2 (10/4=2 with a remainder 2)
  611. 25.68 MOD 6.99=5 (26/7=3 with a remainder 5)
  612. Modulus arithmetic follows integer division in order of
  613. precedence.
  614. GENERAL INFORMATION ABOUT MICROSOFT BASIC Page 1-12
  615. 1.8.1.2 Overflow And Division By Zero -
  616. If, during the evaluation of an expression, division by zero
  617. is encountered, the "Division by zero" error message is
  618. displayed, machine infinity with the sign of the numerator
  619. is supplied as the result of the division, and execution
  620. continues. If the evaluation of an exponentiation operator
  621. results in zero being raised to a negative power, the
  622. "Division by zero" error message is displayed, positive
  623. machine infinity is supplied as the result of the
  624. exponentiation, and execution continues.
  625. If overflow occurs, the "Overflow" error message is
  626. displayed, machine infinity with the algebraically correct
  627. sign is supplied as the result, and execution continues.
  628. 1.8.2 Relational Operators
  629. Relational operators are used to compare two values. The
  630. result of the comparison is either "true" (-1) or "false"
  631. (0). This result may then be used to make a decision
  632. regarding program flow. (See "IF" statements, Section
  633. 2.26.)
  634. The relational operators are
  635. Operator Relation Tested Example
  636. = Equality X=Y
  637. <> Inequality X<>Y
  638. < Less than X<Y
  639. > Greater than X>Y
  640. <= Less than or equal to X<=Y
  641. >= Greater than or equal to X>=Y
  642. (The equal sign is also used to assign a value to a
  643. variable. See "LET," Section 2.30.)
  644. When arithmetic and relational operators are combined in one
  645. expression, the arithmetic is always performed first. For
  646. example, the expression
  647. X+Y<(T-1)/Z
  648. is true if the value of X plus Y is less than the value of
  649. T-1 divided by Z.
  650. GENERAL INFORMATION ABOUT MICROSOFT BASIC Page 1-13
  651. More examples:
  652. IF SIN(X)<0 GOTO 1000
  653. IF I MOD J<>0 THEN K=K+1
  654. 1.8.3 Logical Operators
  655. Logical operators perform tests on multiple relations, bit
  656. manipulation, or Boolean operations. The logical operator
  657. returns a bitwise result which is either "true" (not zero)
  658. or "false" (zero). In an expression, logical operations are
  659. performed after arithmetic and relational operations. The
  660. outcome of a logical operation is determined as shown in
  661. Table 1. The operators are listed in order of precedence.
  662. GENERAL INFORMATION ABOUT MICROSOFT BASIC Page 1-14
  663. Table 1. Microsoft BASIC Relational Operators Truth Table
  664. NOT
  665. X NOT X
  666. 1 0
  667. 0 1
  668. AND
  669. X Y X AND Y
  670. 1 1 1
  671. 1 0 0
  672. 0 1 0
  673. 0 0 0
  674. OR
  675. X Y X OR Y
  676. 1 1 1
  677. 1 0 1
  678. 0 1 1
  679. 0 0 0
  680. XOR
  681. X Y X XOR Y
  682. 1 1 0
  683. 1 0 1
  684. 0 1 1
  685. 0 0 0
  686. EQV
  687. X Y X EQV Y
  688. 1 1 1
  689. 1 0 0
  690. o 1 0
  691. o 0 1
  692. IMP
  693. X I X IMP Y
  694. 1 1 1
  695. 1 0 0
  696. o 1 1
  697. o 0 1
  698. Just as the relational operators can be used to make
  699. decisions regarding program flow, logical operators can
  700. connect two or more relations and return a true or false
  701. value to be used in a decision (see "IF" statements, Section
  702. 2.26).
  703. Example:
  704. IF D<200 AND F<4 THEN 80
  705. IF I>10 OR K<0 THEN 50
  706. IF NOT P THEN 100
  707. Logical operators work by converting their operands to
  708. GENERAL INFORMATION ABOUT MICROSOFT BASIC Page 1-15
  709. 16-bit, signed, two's complement integers in the range
  710. -32768 to 32767. (If the operands are not in this range, an
  711. error results.) If both operands are supplied as 0 or -1,
  712. logical operators return 0 or -1. The given operation is
  713. performed on these integers in bitwise fashion, i.e., each
  714. bit of the result is determined by the corresnonding bits in
  715. the two operands.
  716. Thus, it is possible to use logical operators to test bytes
  717. for a particular bit pattern. For instance, the AND
  718. operator may be used to "mask" all but one of the bits of a
  719. status byte at a machine I/O port. The OR operator may be
  720. used to "merge" two bytes to create a particular binary
  721. value. The following examples will help demonstrate how the
  722. logical operators work.
  723. 63 AND 16=16 63=binary 111111 and 16=binary
  724. 10000, so 63 AND 16=16.
  725. 15 AND 14=14 15=binary 1111 and 14=binary 1110,
  726. so 15 AND 14=14 (binary 1110).
  727. -1 AND 8=8 -1=binary 1111111111111111 and
  728. 8=binary 1000, so -1 AND 8=8.
  729. 4 OR 2=6 4=binary 100 and 2=binary 10,
  730. so 4 OR 2=6 (binary 110).
  731. 10 OR 10=10 10=binary 1010, so 1010 OR 1010=
  732. 1010 (decimal 10).
  733. -1 OR -2=-1 -1=binary 1111111111111111 and
  734. -2=binary 1111111111111110,
  735. so -1 OR -2=-1. The bit
  736. complement of sixteen zeros is
  737. sixteen ones, which is the
  738. two's complement representation of -1.
  739. NOT X=-(X+1) The two's complement of any integer
  740. is the bit complement plus one.
  741. 1.8.4 Functional Onerators
  742. A function is used in an expression to call a predetermined
  743. operation that is to be performed on an operand. Microsoft
  744. BASIC has "intrinsic" functions that reside in the system,
  745. such as SQR (square root) or SIN (sine). All Microsoft
  746. BASIC intrinsic functions are described in Chapter 3.
  747. Microsoft BASIC also allows "user-defined" functions that
  748. are written by the programmer. See "DEF FN," Section 2.11.
  749. GENERAL INFORMATION ABOUT MICROSOFT BASIC Page 1-16
  750. 1.8.5 String Operations
  751. Strings may be concatenated by using +.
  752. Example:
  753. 10 A$="FILE" : 8$="NAME"
  754. 20 PRINT A$+B$
  755. 30 PRINT "NEW "+A$+B$
  756. RUN
  757. FILENAME
  758. NEW FILENAME
  759. Strings may be compared using the same relational operators
  760. that are used with numbers:
  761. = <> < > <= >=
  762. String comparisons are made by taking one character at a
  763. time from each string and comparing the ASCII codes. If all
  764. the ASCII codes are the same, the strings are equal. If the
  765. ASCII codes differ, the lower code number precedes the
  766. higher. If during string comparison the end of one string
  767. is reached, the shorter string is said to be smaller.
  768. Leading and trailing blanks are significant.
  769. Examples:
  770. "AA"<"AB"
  771. "FILENAME"="FILENAME"
  772. "X&">"X#"
  773. "CL ">"CL"
  774. "kg" >"KG"
  775. "SMYTH"<"SMYTHE"
  776. B$<"9/12/78" where B$="8/12/78"
  777. Thus, string comparisons can be used to test string values
  778. or to alphabetize strings. All string constants used in
  779. comparison expressions must be enclosed in quotation marks.
  780. 1.9 INPUT EDITING
  781. If an incorrect character is entered as a line is being
  782. typed, it can be deleted with the <RUBOUT> key or with
  783. Control-H. Rubout surrounds the deleted character(s) with
  784. backslashes. Control-H has the effect of backspacing over a
  785. character and erasing it. Once a character(s) has been
  786. deleted, simply continue typing the line as desired.
  787. To delete a line that is in the process of being typed, type
  788. Control-U. A carriage return is executed automatically
  789. after the line is deleted.
  790. GENERAL ENFORMATION ABOUT MICROSOFT BASIC Page 1-17
  791. To correct program lines for a program that is currently in
  792. memory, simply retype the line using the same line number.
  793. Microsoft BASIC will automatically replace the old line with
  794. the new line.
  795. More sophisticated editing capabilities are provided. See
  796. "EDIT," Section 2.16.
  797. To delete the entire program currently residing in memory,
  798. enter the NEW command. (See Section 2.41.) NEW is usually
  799. used to clear memory prior to entering a new program.
  800. 1.10 ERROR MESSAGES
  801. If an error causes program execution to terminate, an error
  802. message is printed. For a complete list of Microsoft BASIC
  803. error codes and error messages, see Appendix A.
  804. <<< blank page >>>
  805. Chapter 2 Microsoft BASIC Commands and Statements
  806. Introduction
  807. 2.1 AUTO
  808. 2.2 CALL
  809. 2.3 CHAIN
  810. 2.4 CLEAR
  811. 2.5 CLOAD
  812. 2.6 CLOSE
  813. 2.7 COMMON
  814. 2.8 CONT
  815. 2.9 CSAVE
  816. 2.10 DATA
  817. 2.11 DEF FN
  818. 2.12 DEFINT/SNG/DBL/STR
  819. 2.13 DEF USR
  820. 2.14 DELETE
  821. 2.15 DIM
  822. 2.16 EDIT
  823. 2.17 END
  824. 2.18 ERASE
  825. 2.19 ERR and ERL Variables
  826. 2.20 ERROR
  827. 2.21 FIELD
  828. 2.22 FOR...NEXT
  829. 2.23 GET
  830. 2.24 GOSUB...RETURN
  831. 2.25 GOTO
  832. 2.26 IF-THEN[...ELSE] and IF...GOTO
  833. 2.27 INPUT
  834. 2.28 INPUT#
  835. 2.29 KILL
  836. 2.30 LET
  837. 2.31 LINE INPUT
  838. 2.32 LINE INPUT#
  839. 2.33 LIST
  840. 2.34 LLIST
  841. 2.35 LOAD
  842. 2.36 LPRINT and LPRINT USING
  843. 2.37 LSET and RSET
  844. 2.38 MERGE
  845. 2.39 MID$
  846. 2.40 NAME
  847. 2.41 NEW
  848. 2.42 NULL
  849. 2.43 ON ERROR GOTO
  850. 2.44 ON...GOSUB and ON...GOTO
  851. 2.45 OPEN
  852. 2.46 OPTION BASE
  853. 2.47 OUT
  854. 2.48 POKE
  855. 2.49 PRINT
  856. 2.50 PRINT USING
  857. 2.51 PRINT# and PRINT# USING
  858. 2.52 PUT
  859. GENERAL INFORMATION ABOUT MICROSOFT BASIC
  860. 2.53 RANDOMIZE
  861. 2.54 READ
  862. 2.55 REM
  863. 2.56 RENUM
  864. 2.57 RESTORE
  865. 2.58 RESUME
  866. 2.59 RUN
  867. 2.60 SAVE
  868. 2.61 STOP
  869. 2.62 SWAP
  870. 2.63 TRON/TROFF
  871. 2.64 WAIT
  872. 2.65 WHILE...WEND
  873. 2.66 WIDTH
  874. 2.67 WRITE
  875. 2.68 WRITE#
  876. CHAPTER 2
  877. MICROSOFT BASIC COMMANDS AND STATEMENTS
  878. Microsoft BASIC commands and statements are described in
  879. this chapter. Each description is formatted as follows:
  880. Format Shows the correct format for the instruction.
  881. See the "Introduction" to this manual for syntax
  882. notation.
  883. Purpose Tells what the instruction is used for.
  884. Remarks Describes in detail how the instruction
  885. is used.
  886. Example Shows sample programs or program segments
  887. that demonstrate the use of the instruction.
  888. Note Describes special cases or provides additional
  889. pertinent information.
  890. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-2
  891. 2.1 AUTO
  892. Format AUTO [dine number>[,<increment>]]
  893. Purpose To generate a line number automatically after
  894. every carriage return.
  895. Remarks AUTO begins numbering at <line number> and
  896. increments each subsequent line number by
  897. <increment>. The default for both values is 10.
  898. If <line number> is followed by a comma but
  899. <increment> is not specified, the last increment
  900. specified in an AUTO command is assumed.
  901. If AUTO generates a line number that is already
  902. being used, an asterisk is printed after the
  903. number to warn the user that any input will
  904. replace the existing line. However, typing a
  905. carriage return immediately after the asterisk
  906. will save the line and generate the next line
  907. number.
  908. AUTO is terminated by typing Control-C. The
  909. line in which Control-C is typed is not saved.
  910. After Control-C is typed, Microsoft BASIC
  911. returns to command level.
  912. Example AUTO 100,50 Generates line numbers 100,
  913. 150, 200 ..
  914. AUTO Generates line numbers 10,
  915. 20, 30, 40 ...
  916. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-3
  917. 2.2 CALL
  918. Format CALL <variable name>[(<argument list>)]
  919. Purpose To call an assembly language subroutine.
  920. Remarks: The CALL statement is one way to transfer
  921. program flow to an external subroutine. (See
  922. also the USR function, Section 3.41)
  923. <variable name> contains an address that is the
  924. starting point in memory of the subroutine.
  925. <variable name> may not be an array variable
  926. name. <argument list> contains the arguments
  927. that are passed to the external subroutine.
  928. <argument list> may contain only variables.
  929. The CALL statement generates the same calling
  930. sequence used by Microsoft(TM) FORTRAN,
  931. Microsoft(TM) COBOL, and Microsoft(TM) BASIC
  932. Compilers.
  933. Example 110 MYROUT=&HD000
  934. 120 CALL MYROUT(I,J,K)
  935. .
  936. .
  937. .
  938. Note In a Microsoft BASIC Compiler program, line 110
  939. is not required because the address of MYROUT
  940. will be assigned by the linking loader at load
  941. time.
  942. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-4
  943. 2.3 CHAIN
  944. Format CHAIN [MERGE ]<filename>[,[<line number exp>]
  945. [,ALL][,DELETE <range>]]
  946. Purpose To call a program and pass variables to it from
  947. the current program.
  948. Remarks <filename> is the name of the program that is
  949. called.
  950. The COMMON statement may be used to pass
  951. variables (see Section 2.7).
  952. Example 1
  953. 10 REM THIS PROGRAM DEMONSTRATES CHAINING USING
  954. COMMON TO PASS VARIABLES.
  955. 20 REM SAVE THIS MODULE ON DISK AS "PROG1"
  956. USING THE A OPTION.
  957. 30 DIM A$(2),B$(2)
  958. 40 COMMON A$(),B$()
  959. 50 A$(1)="VARIABLES IN COMMON MUST BE ASSIGNED"
  960. 60 A$(2)="VALUES BEFORE CHAINING."
  961. 70 B$(1)="": B$(2) =""
  962. 80 CHAIN "PROG2"
  963. 90 PRINT: PRINT B$(1): PRINT: PRINT B$(2):
  964. PRINT
  965. 100 END
  966. <line number exp> is a line number or an
  967. expression that evaluates to a line number in
  968. the called program. It is the starting point
  969. for execution of the called program. If it is
  970. omitted, execution begins at the first line.
  971. Example 2
  972. 10 REM THE STATEMENT "DIM A$(2),B$(2)"
  973. MAY ONLY BE EXECUTED ONCE.
  974. 20 REM HENCE, IT DOES NOT APPEAR IN THIS
  975. MODULE.
  976. 30 REM SAVE THIS MODULE ON THE DISK AS "PROG2"
  977. USING THE A OPTION,
  978. 40 COMMON A$(),B$()
  979. 50 PRINT: PRINT A$(1);A$(2)
  980. 60 B$(1)="NOTE HOW THE OPTION OF SPECIFYING
  981. A STARTING LINE NUMBER"
  982. 70 B$(2)="WHEN CHAINING AVOIDS THE DIMENSION
  983. STATEMENT IN 'PROG1'."
  984. 80 CHAIN "PROG1",90
  985. 90 END
  986. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-S
  987. <line number exp> is not affected by a RENUM
  988. command.
  989. With the ALL option, every variable in the
  990. current program is passed to the called program.
  991. If the ALL option is omitted, the current
  992. program must contain a COMMON statement to list
  993. the variables that are passed. See Section 2.7.
  994. The MERGE option allows a subroutine to be
  995. brought into the BASIC program as an overlay.
  996. That is, a MERGE operation is performed with the
  997. current program and the called program. The
  998. called program must be an ASCII file if it is to
  999. be MERGEd.
  1000. After an overlay is brought in, it is usually
  1001. desirable to delete it so that a new overlay may
  1002. be brought in. To do this, use the DELETE
  1003. option.
  1004. Example 3
  1005. 10 REM THIS PROGRAM DEMONSTRATES CHAINING USING
  1006. THE MERGE AND ALL OPTIONS.
  1007. 20 REM SAVE THIS MODULE ON THE DISK AS
  1008. "MAINPRG".
  1009. 30 A$="MAINPRG"
  1010. 40 CHAIN MERGE "OVRLAY1",1010,ALL
  1011. 50 END
  1012. 1000 REM SAVE THIS MODULE ON THE DISK AS
  1013. "OVRLAY1" USING THE A OPTION.
  1014. 1010 PRINT A$; " HAS CHAINED TO OVRLAY1."
  1015. 1020 A$="OVRLAY1"
  1016. 1030 B$="OVRLAY2"
  1017. 1040 CHAIN MERGE "OVRLAY2",1010,ALL,
  1018. DELETE 1000-1050
  1019. 1050 END
  1020. 1000 REM SAVE THIS MODULE ON THE DISK AS
  1021. "ORLAY2" USING THE A OPTION.
  1022. 1010 PRINT A$; " HAS CHAINED TO ";B$;"."
  1023. 1020 END
  1024. The line numbers in <range> are affected by the
  1025. RENUM command.
  1026. Note The CHAIN statement with MERGE option leaves the
  1027. files open and preserves the current OPTION BASE
  1028. setting.
  1029. If the MERGE option is omitted, CHAIN does not
  1030. preserve variable types or user-defined
  1031. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-6
  1032. functions for use by the chained program. That
  1033. is, any DEFINT, DEFSNG, DEFDBL, DEFSTR, or DEFFN
  1034. statements containing shared variables must be
  1035. restated in the chained program.
  1036. The Microsoft BASIC Compiler does not support
  1037. the ALL, MERGE, DELETE, and <line number exp>
  1038. options to CHAIN. Thus, the statement format is
  1039. CHAIN <filename>. If you wish to maintain
  1040. compatibility with Microsoft BASIC Compiler, it
  1041. is recommended that COMMON be used to pass
  1042. variables and that overlays not be used. The
  1043. CHAIN statement leaves the files open during
  1044. CHAINing.
  1045. When using the MERGE option, user-defined
  1046. functions should be placed before any CHAIN
  1047. MERGE statements in the program. Otherwise, the
  1048. user-defined functions will be undefined after
  1049. the merge is complete.
  1050. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-7
  1051. 2.4 CLEAR
  1052. Format CLEAR [,[<expression1>][,<expression2>]]
  1053. Purpose To set all numeric variables to zero, all string
  1054. variables to null, and to close all open files;
  1055. and, optionally, to set the end of memory and
  1056. the amount of stack space.
  1057. Remarks <expressionl> is a memory location which, if
  1058. specified, sets the highest location available
  1059. for use by Microsoft BASIC.
  1060. <expression2> sets aside stack space for
  1061. Microsoft BASIC. The default is 512 bytes or
  1062. one-eighth of the available memory, whichever is
  1063. smaller.
  1064. Note Microsoft BASIC allocates string space
  1065. dynamically. An "Out of string space" error
  1066. occurs only if there is no free memory left for
  1067. Microsoft BASIC to use.
  1068. Microsoft BASIC Compiler supports the CLEAR
  1069. statement with the restriction that
  1070. <expression1> and <expression2> must be integer
  1071. expressions. If a value of 0 is given for
  1072. either expression, the appropriate default is
  1073. used. The default stack size is 512 bytes, and
  1074. the default top of memory is the current top of
  1075. memory. The CLEAR statement performs the
  1076. following actions:
  1077. Closes all files.
  1078. Clears all COMMON and user variables.
  1079. Resets the stack and string space.
  1080. Releases all disk buffers.
  1081. Examples CLEAR
  1082. CLEAR ,32768
  1083. CLEAR ,2000
  1084. CLEAR ,32768,2000
  1085. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-8
  1086. 2.5 CLOAD
  1087. Formats CLOAD <filename>
  1088. CLOAD? <filename>
  1089. CLOAD* <array name>
  1090. Purpose To load a program or an array from cassette tape
  1091. into memory.
  1092. Remarks CLOAD executes a NEW command before it loads the
  1093. program from cassette tape. <filename> is the
  1094. string expression or the first character of the
  1095. string expression that was specified when the
  1096. program was CSAVEd.
  1097. CLOAD? verifies tapes by comparing the program
  1098. currently in memory with the file on tape that
  1099. has the same filename. If they are the same,
  1100. Microsoft BASIC prints "Ok". If not, Microsoft
  1101. BASIC prints "NO GOOD".
  1102. CLOAD* loads a numeric array that has been saved
  1103. on tape. The data on tape is loaded into the
  1104. array called <array name> specified when the
  1105. array was CSAVE*ed.
  1106. CLOAD and CLOAD? are always entered at command
  1107. level as direct mode commands. CLOAD* may be
  1108. entered at command level or used as a program
  1109. statement. Make sure the array has been
  1110. DIMensioned before it is loaded. Microsoft
  1111. BASIC always returns to command level after a
  1112. CLOAD, CLOAD?, or CLOAD* is executed. Before a
  1113. CLOAD is executed, make sure the cassette
  1114. recorder is properly connected and in the play
  1115. mode, and the tape is positioned correctly.
  1116. See also "CSAVE," Section 2.9.
  1117. Note CLOAD and CSAVE are not included in all
  1118. implementations of Microsoft BASIC.
  1119. Example CLOAD "MAX2"
  1120. Loads file "MAX2" into memory.
  1121. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-9
  1122. 2.6 CLOSE
  1123. Format CLOSE [[#]<file number>[,[#]<file number...>]]
  1124. Purpose To conclude I/O to a disk file.
  1125. Remarks <file number> is the number under which the file
  1126. was OPENed. A CLOSE with no arguments closes
  1127. all open files.
  1128. The association between a particular file and
  1129. file number terminates upon execution of a CLOSE
  1130. statement. The file may then be reOPENed using
  1131. the same or a different file number; likewise,
  1132. that file number may now be reused to OPEN any
  1133. file.
  1134. A CLOSE for a sequential output file writes the
  1135. final buffer of output.
  1136. The END statement and the NEW command always
  1137. CLOSE all disk files automatically. (STOP does
  1138. not close disk files.)
  1139. Example See "Microsoft BASIC Disk I/O," in the Microsoft
  1140. BASIC User's Guide.
  1141. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-10
  1142. 2.7 COMMON
  1143. Format COMMON <list of variables>
  1144. Purpose To pass variables to a CHAINed program.
  1145. Remarks The COMMON statement is used in conjunction with
  1146. the CHAIN statement. COMMON statements may
  1147. appear anywhere in a program, though it is
  1148. recommended that they appear at the beginning.
  1149. The same variable cannot appear in more than one
  1150. COMMON statement. Array variables are specified
  1151. by appending '()" to the variable name. If all
  1152. variables are to be passed, use CHAIN with the
  1153. ALL option and omit the COMMON statement.
  1154. Example 100 COMMON A,B,C,D(),G$
  1155. 110 CHAIN "PROG3",10
  1156. Note Microsoft BASIC Compiler supports a modified
  1157. version of the COMMON statement. The COMMON
  1158. statement must appear in a program before any
  1159. executable statements. The current
  1160. nonexecutable statements are:
  1161. COMMON
  1162. DEFDBL, DEFINT, DEFSNG, DEFSTR
  1163. DIM
  1164. OPTION BASE
  1165. REM
  1166. $INCLUDE
  1167. Array variables used in a COMMON statement must
  1168. be declared in a preceding DIM statement.
  1169. The standard form of the COMMON statement is
  1170. referred to as blank COMMON. Microsoft FORTRAN
  1171. Compiler-style named COMMON areas are also
  1172. supported; however, the variables are not
  1173. preserved across CHAINs. The syntax for named
  1174. COMMON is:
  1175. COMMON /<name>/ <list of variables>
  1176. where <name> consists of 1 to 6 alphanumeric
  1177. characters starting with a letter. This is
  1178. useful for communicating with Microsoft FORTRAN
  1179. Compiler and assembly language routines without
  1180. having to explicitly pass parameters in the CALL
  1181. statement.
  1182. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-11
  1183. The blank COMMON size and order of variables
  1184. must be the same in the CHAINing and CHAINed
  1185. programs. With Microsoft BASIC Compiler, the
  1186. best way to insure this is to place all blank
  1187. COMMON declarations in a single include file and
  1188. use the $INCLUDE statement in each program.
  1189. For example:
  1190. MENU .BAS
  1191. 10 $INCLUDE COMDEF
  1192. .
  1193. .
  1194. . 1000 CHAIN "PROG1"
  1195. PROG1.BAS
  1196. 10 $INCLUDE COMDEF
  1197. .
  1198. .
  1199. . 2000 CHAIN "MENU"
  1200. COMDEF.BAS
  1201. 100 DIM A(100),B$(200)
  1202. 110 COMMON I,J,K,A()
  1203. 120 COMMON A$,B$(),X,Y,Z
  1204. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-12
  1205. 2.8 CONT
  1206. Format CONT
  1207. Purpose To continue program execution after a Control-C
  1208. has been typed or a STOP or END statement has
  1209. been executed.
  1210. Remarks Execution resumes at the point where the break
  1211. occurred. If the break occurred after a prompt
  1212. from an INPUT statement, execution continues
  1213. with the reprinting of the prompt ("?" or prompt
  1214. string).
  1215. CONT is usually used in conjunction with STOP
  1216. for debugging. When execution is stopped,
  1217. intermediate values may be examined and changed
  1218. using direct mode statements. Execution may be
  1219. resumed with CONT or a direct mode GOTO, which
  1220. resumes execution at a specified line number.
  1221. CONT may be used to continue execution after an
  1222. error has occurred.
  1223. CONT is invalid if the program has been edited
  1224. during the break.
  1225. Example See "STOP," Section 2.61.
  1226. MICROSOFT BASIC CONIMANDS AND STATEMENTS Page 2-13
  1227. 2.9 CSAVE
  1228. Formats CSAVE <string expression>
  1229. CSAVE* <array variable name>
  1230. Purpose To save the program or an array currently in
  1231. memory on cassette tape.
  1232. Remarks Each program or array saved on tape is
  1233. identified by a filename. When the command
  1234. CSAVE <string expression> is executed, Microsoft
  1235. BASIC saves the program currently in memory on
  1236. tape and uses the first character in <string
  1237. expression> as the filename. <string
  1238. expression> may be more than one character, but
  1239. only the first character is used for the
  1240. filename.
  1241. When the command CSAVE* <array variable name> is
  1242. executed, Microsoft BASIC saves the specified
  1243. array on tape. The array must be a numeric
  1244. array. The elements of a multidimensional array
  1245. are saved with the leftmost subscript changing
  1246. fastest. For example, when the 2-dimensional
  1247. array specified by DIM A(2,2) is saved (see
  1248. "DIM," Section 2.15), the array elements are
  1249. saved in the following order:
  1250. 0,0
  1251. 1,0
  1252. 2,0
  1253. 0,1
  1254. 1,1
  1255. 2,1
  1256. 0,2
  1257. 1,2
  1258. 2,2
  1259. CSAVE may be used as a program statement or as a
  1260. direct mode command.
  1261. Before a CSAVE or CSAVE* is executed, make sure
  1262. the cassette recorder is properly connected and
  1263. in the record mode.
  1264. See also "CLOAD," Section 2.5.
  1265. Note CSAVE and CLOAD are not included in all
  1266. implementations of Microsoft BASIC.
  1267. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-14
  1268. Example CSAVE "TIMER"
  1269. Saves the program currently in memory
  1270. on cassette under filename "TIMER".
  1271. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-15
  1272. 2.10 DATA
  1273. Format DATA <list of constants>
  1274. Purpose To store the numeric and string constants that
  1275. are accessed by the program's READ statement(s).
  1276. (See "READ," Section 2.54.)
  1277. Remarks DATA statements are nonexecutable and may be
  1278. placed anywhere in the program. A DATA
  1279. statement may contain as many constants as will
  1280. fit on a line (separated by commas). Any number
  1281. of DATA statements may be used in a program.
  1282. READ statements access DATA statements in order
  1283. (by line number). The data contained therein
  1284. may be thought of as one continuous list of
  1285. items, regardless of how many items are on a
  1286. line or where the lines are placed in the
  1287. program.
  1288. <list of constants> may contain numeric
  1289. constants in any format; i.e., fixed-point,
  1290. floating-point, or integer. (No numeric
  1291. expressions are allowed in the list.) String
  1292. constants in DATA statements must be surrounded
  1293. by double quotation marks only if they contain
  1294. commas, colons, or significant leading or
  1295. trailing spaces. Otherwise, quotation marks are
  1296. not needed.
  1297. The variable type (numeric or string) given in
  1298. the READ statement must agree with the
  1299. corresponding constant in the DATA statement.
  1300. DATA statements may be reread from the beginning
  1301. by use of the RESTORE statement (Section 2.57).
  1302. Example See "READ," Section 2.54.
  1303. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-16
  1304. 2.11 DEF FN
  1305. Format DEF FN<name>[<parameter list>)]=<function definition>
  1306. Purpose To define and name a function that is written by
  1307. the user.
  1308. Remarks <name> must be a legal variable name. This
  1309. name, preceded by FN, becomes the name of the
  1310. function.
  1311. <parameter list> consists of those variable
  1312. names in the function definition that are to be
  1313. replaced when the function is called. The items
  1314. in the list are separated by commas.
  1315. <function definition> is an expression that
  1316. performs the operation of the function. It is
  1317. limited to one line. Variable names that appear
  1318. in this expression serve only to define the
  1319. function; they do not affect program variables
  1320. that have the same name. A variable name used
  1321. in a function definition may or may not appear
  1322. in the parameter list. If it does, the value of
  1323. the parameter is supplied when the function is
  1324. called. Otherwise, the current value of the
  1325. variable is used.
  1326. The variables in the parameter list represent,
  1327. on a one-to-one basis, the argument variables or
  1328. values that will be given in the function call.
  1329. This statement may define either numeric or
  1330. string functions. If a type is specified in the
  1331. function name, the value of the expression is
  1332. forced to that type before it is returned to the
  1333. calling statement. If a type is specified in
  1334. the function name and the argument type does not
  1335. match, a 'Tyne mismatch' error occurs.
  1336. A DEF FN statement must be executed before the
  1337. function it defines may be called. If a
  1338. function is called before it has been defined,
  1339. an "Undefined user function" error occurs. DEF
  1340. FN is illegal in the direct mode.
  1341. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-17
  1342. Example .
  1343. .
  1344. 410 DEF FNAB(X,Y)=X^3/Y^2
  1345. 420 T=FNAB(I,J)
  1346. .
  1347. .
  1348. Line 410 defines the function FNAB. The
  1349. function is called in line 420.
  1350. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-18
  1351. 2.12 DEFINT/SNG/DBL/STR
  1352. Format DEF<type> <range(s) of letters>
  1353. where <type> is INT, SNG, DBL, or STR
  1354. Purpose To declare variable types as integer, single
  1355. precision, double precision, or string.
  1356. Remarks: Any variable names beginning with the letter(s)
  1357. specified in <range of letters> will be
  1358. considered the type of variable specified in the
  1359. <type> portion of the statement. However, a
  1360. type declaration character always takes
  1361. precedence over a DEFtype statement. (See
  1362. "Variable Names and Declaration Characters,"
  1363. Section 1.6.1.)
  1364. If no type declaration statements are
  1365. encountered, Microsoft BASIC assumes all
  1366. variables without declaration characters are
  1367. single precision variables.
  1368. Examples 10 DEFDBL L-P All variables beginning with
  1369. the letters L, M, N, O, and P
  1370. will be double precision
  1371. variables.
  1372. 10 DEFSTR A All variables beginning with
  1373. the letter A will be string
  1374. variables.
  1375. 10 DEFINT I-N,W-Z
  1376. All variable beginning with
  1377. the letters I, J, K, L, M,
  1378. N, W, X, Y, Z will be integer
  1379. variables.
  1380. MICROSOFT BASIC COKMANDS AND STATEMENTS Page 2-19
  1381. 2.13 DEF USR
  1382. Format DEF USR[<digit>]=<integer expression>
  1383. Purpose To specify the starting address of an assembly
  1384. language subroutine.
  1385. Remarks <digit> may be any digit from 0 to 9. The digit
  1386. corresponds to the number of the USR routine
  1387. whose address is being specified. If <digit> is
  1388. omitted, DEF USR0 is assumed. The value of
  1389. <integer expression> is the starting address of
  1390. the USR routine. See "Assembly Language
  1391. Subroutines," in the Microsoft BASIC User's
  1392. Guide.
  1393. Any number of DEF USR statements may appear in a
  1394. program to redefine subroutine starting
  1395. addresses, thus allowing access to as many
  1396. subroutines as necessary.
  1397. Example
  1398. 200 DEF USR0=24000
  1399. 210 X=USR0(Y^2/2.89)
  1400. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-20
  1401. 2.14 DELETE
  1402. Format DELETE [<line number>][-<line number>]
  1403. Purpose To delete program lines.
  1404. Remarks Microsoft BASIC always returns to command level
  1405. after a DELETE is executed. If <line number>
  1406. does not exist, an "Illegal function call" error
  1407. occurs.
  1408. Examples DELETE 40 Deletes line 40.
  1409. DELETE 40-100 Deletes lines 40 through
  1410. 100, inclusive.
  1411. DELETE -40 Deletes all lines up to
  1412. and including line 40.
  1413. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-21
  1414. 2.15 DIM
  1415. Format DIM <list of subscripted variables>
  1416. Purpose To specify the maximum values for array variable
  1417. subscripts and allocate storage accordingly.
  1418. Remarks If an array variable name is used without a DIM
  1419. statement, the maximum value of the array's
  1420. subscript(s) is assumed to be 10. If a
  1421. subscript is used that is greater than the
  1422. maximum specified, a "Subscript out of range"
  1423. error occurs. The minimum value for a subscript
  1424. is always 0, unless otherwise specified with the
  1425. OPTION BASE statement (see Section 2.46).
  1426. The DIM statement sets all the elements of the
  1427. specified arrays to an initial value of zero.
  1428. Theoretically, the maximum number of dimensions
  1429. allowed in a DIM statement is 255. In reality,
  1430. however, that number would be impossible, since
  1431. the name and punctuation are also counted as
  1432. spaces on the line, and the line itself has a
  1433. limit of 255 characters. The number of
  1434. dimensions is further limited by the amount of
  1435. available memory.
  1436. Example 10 DIM A(20)
  1437. 20 FOR I=0 TO 20
  1438. 30 READ A(I)
  1439. 40 NEXT I
  1440. .
  1441. .
  1442. .
  1443. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-22
  1444. 2.16 EDIT
  1445. Format EDIT <line number>
  1446. Purpose To enter edit mode at the specified line.
  1447. Remarks In edit mode, it is possible to edit portions of
  1448. a line without retyping the entire line. Upon
  1449. entering edit mode, BASIC types the line number
  1450. of the line to be edited, then it types a space
  1451. and waits for an edit mode subcommand.
  1452. Edit Mode Subcommands
  1453. Edit mode subcommands are used to move the cursor or to
  1454. insert, delete, replace, or search for text within a line.
  1455. The subcommands are not echoed. However, most of the edit
  1456. mode subcommands may be preceded by an integer which causes
  1457. the command to be executed that number of times. When an
  1458. integer is not specified, it is assumed to be 1.
  1459. Edit mode subcommands may be categorized according to the
  1460. following functions:
  1461. 1. Moving the cursor.
  1462. 2. Inserting text.
  1463. 3. Deleting text.
  1464. 4. Finding text.
  1465. 5. Replacing text.
  1466. 6. Ending and restarting edit mode.
  1467. 7. Entering edit mode from a syntax error.
  1468. Note In the descriptions that follow, <ch> represents
  1469. any character, <text> represents a string of
  1470. characters of arbitrary length, [i] represents
  1471. an optional integer (the default is 1), and $
  1472. represents the Escape (or Altmode) key.
  1473. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-23
  1474. 1. Moving the Cursor
  1475. Space bar
  1476. Use the space bar to move the cursor to the
  1477. right. [i]Space bar moves the cursor i spaces
  1478. to the right. Characters are printed as you
  1479. space over them.
  1480. Rubout In edit mode, fi]Rubout moves the cursor i
  1481. spaces to the left (backspaces) . Characters are
  1482. printed as you backspace over them.
  1483. 2. Inserting Text
  1484. I I<text>$ inserts <text> at the current cursor
  1485. position. The inserted characters are printed
  1486. on the terminal. To terminate insertion, press
  1487. Escape. If a <carriage return> is typed during
  1488. an Insert command, the effect is the same as
  1489. pressing Escape and then <carriage return>.
  1490. During an Insert command, the Rubout, Delete, or
  1491. Underscore key on the terminal may be used to
  1492. delete characters to the left of the cursor.
  1493. Rubout will print out the characters as you
  1494. backspace over them. Delete and underscore will
  1495. print an Underscore for each character that you
  1496. backspace over. If an attempt is made to insert
  1497. a character that will make the line longer than
  1498. 255 characters, a bell (Control-G) sounds and
  1499. the character is not printed.
  1500. X The X subcommand extends the line. X moves the
  1501. cursor to the end of the line, enters insert
  1502. mode, and allows insertion of text as if an
  1503. Insert command had been given. When you are
  1504. finished extending the line, press Escape or
  1505. carriage return.
  1506. 3. Deleting Text
  1507. D [i]D deletes i characters to the right of the
  1508. cursor. The deleted characters are echoed
  1509. between backslashes, and the cursor is
  1510. positioned to the right of the last character
  1511. deleted. If there are fewer than i characters
  1512. to the right of the cursor, iD deletes the
  1513. remainder of the line.
  1514. H H deletes all characters to the right of the
  1515. cursor and then automatically enters insert
  1516. mode. H is useful for extending a line or
  1517. replacing statements at the end of a line.
  1518. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-24
  1519. 4. Finding Text
  1520. S The subcommand [i]S<ch> searches for the ith
  1521. occurrence of <ch> and positions the cursor
  1522. before it. The character at the current cursor
  1523. position is not included in the search. If <ch>
  1524. is not found, the cursor stops at the end of the
  1525. line. All characters passed over during the
  1526. search are printed.
  1527. K The subcommand [i]K<ch> is similar to [i]S<ch>,
  1528. except all the characters passed over in the
  1529. search are deleted. The cursor is positioned
  1530. before <ch>, and the deleted characters are
  1531. enclosed in backslashes.
  1532. 5. Replacing Text
  1533. C The subcommand C<ch> changes the next character
  1534. to <ch>. If you wish to change the next i
  1535. characters, use the subcommand iC, followed by
  1536. as many characters as are specified by i. After
  1537. the ith new character is typed, change mode is
  1538. exited and you will return to edit mode.
  1539. 6. Ending and Restarting Edit Mode
  1540. <cr> Typing a <carriage return> prints the remainder
  1541. of the line, saves the changes you made, and
  1542. exits edit mode.
  1543. E The E subcommand has the same effect as
  1544. <carriage return>, except the remainder of the
  1545. line is not printed.
  1546. Q The Q subcommand returns to Microsoft BASIC
  1547. command level, without saving any of the changes
  1548. that were made to the line in edit mode.
  1549. L The L subcommand lists the remainder of the line
  1550. (saving any changes made so far) and repositions
  1551. the cursor at the beginning of the line, still
  1552. in edit mode. L is usually used to list the
  1553. line when you first enter edit mode.
  1554. A The A subcommand lets you begin editing a line
  1555. over again. It restores the original line and
  1556. repositions the cursor at the beginning.
  1557. Control-A
  1558. To enter edit mode on the line you are currently
  1559. typing, type Control-A. Microsoft BASIC
  1560. responds with a <carriage return>, an
  1561. exclamation point (!), and a space. The cursor
  1562. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-25
  1563. will be positioned at the first character in the
  1564. line. Proceed by typing an edit mode
  1565. subcommand.
  1566. Remember, if you have just entered a line and
  1567. wish to go back and edit it, the command "EDIT."
  1568. will enter edit mode at the current line. (The
  1569. line number symbol "." always refers to the
  1570. current line.)
  1571. If an unrecognizable command or illegal
  1572. character is input to Microsoft BASIC while in
  1573. edit mode, BASIC sends a Control-G (bell) to the
  1574. terminal, and the command or character is
  1575. ignored.
  1576. 7. Entering Edit Mode from a Syntax Error
  1577. When a syntax error is encountered during
  1578. execution of a program, Microsoft BASIC
  1579. automatically enters edit mode at the line that
  1580. caused the error. For example:
  1581. 10 K=2(4)
  1582. RUN
  1583. ?Syntax error in 10
  1584. 10
  1585. When you finish editing the line and press
  1586. <carriage return> (or the E subcommand),
  1587. Microsoft BASIC reinserts the line. This causes
  1588. all variable values to be lost. To preserve the
  1589. variable values for examination, first exit edit
  1590. mode with the Q subcommand. Microsoft BASIC
  1591. will return to command level, and all variable
  1592. values will be preserved.
  1593. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-26
  1594. 2.17 END
  1595. Format END
  1596. Purpose To terminate program execution, close all files,
  1597. and return to command level.
  1598. Remarks END statements may be placed anywhere in the
  1599. program to terminate execution. Unlike the STOP
  1600. statement, END does not cause a "Break in line
  1601. nnnnn" message to be printed. An END statement
  1602. at the end of a program is optional. Microsoft
  1603. BASIC always returns to command level after an
  1604. END is executed.
  1605. Example 520 IF K>1000 THEN END ELSE GOTO 20
  1606. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-27
  1607. 2.18 ERASE
  1608. Format ERASE <list of array variables>
  1609. Purpose To eliminate arrays from a program.
  1610. Remarks Arrays may be redimensioned after they are
  1611. ERASEd, or the previously allocated array space
  1612. in memory may be used for other purposes. If an
  1613. attempt is made to redimension an array without
  1614. first ERASEing it, a "Redimensioned array" error
  1615. occurs.
  1616. Microsoft BASIC Compiler does not support ERASE.
  1617. Example
  1618. .
  1619. .
  1620. .
  1621. 450 ERASE A,B
  1622. 460 DIM B(99)
  1623. .
  1624. .
  1625. .
  1626. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-28
  1627. 2.19 ERR AND ERL VARIABLES
  1628. When an error handling routine is entered, the
  1629. variable ERR contains the error code for the
  1630. error and the variable ERL contains the line
  1631. number of the line in which the error was
  1632. detected. The ERR and ERL variables are usually
  1633. used in IF...THEN statements to direct program
  1634. flow in the error handling routine.
  1635. If the statement that caused the error was a
  1636. direct mode statement, ERL will contain 65535.
  1637. To test whether an error occurred in a direct
  1638. statement, use IF 65535=ERL THEN
  1639. Otherwise, use
  1640. IF ERR=error code THEN ...
  1641. IF ERL=line number THEN ...
  1642. If the line number is not on the right side of
  1643. the relational operator, it cannot be renumbered
  1644. with RENUM. Because ERL and ERR are reserved
  1645. variables, neither may appear to the left of the
  1646. equal sign in a LET (assignment) statement.
  1647. Microsoft BASIC error codes are listed in
  1648. Appendix A.
  1649. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-29
  1650. 2.20 ERROR
  1651. Format ERROR <integer expression>
  1652. Purpose To simulate the occurrence of a BASIC error, or
  1653. to allow error codes to be defined by the user.
  1654. Remarks The value of <integer expression> must be
  1655. greater than 0 and less than 255. If the value
  1656. of <integer expression> equals an error code
  1657. already in use by BASIC (see Appendix A), the
  1658. ERROR statement will simulate the occurrence of
  1659. that error and the corresoonding error message
  1660. will be printed. (See Example 1.)
  1661. To define your own error code, use a value that
  1662. is greater than any used by Microsoft BASIC
  1663. error codes. (It is preferable to use the
  1664. highest available values, so compatibility may
  1665. be maintained when more error codes are added to
  1666. Microsoft BASIC.) This user-defined error code
  1667. may then be conveniently handled in an error
  1668. handling routine. (See Example 2.)
  1669. If an ERROR statement specifies a code for which
  1670. no error message has been defined, Microsoft
  1671. BASIC responds with the "Unprintable error"
  1672. error message. Execution of an ERROR statement
  1673. for which there is no error handling routine
  1674. causes an error message to be printed and
  1675. execution to halt.
  1676. Example 1 LIST
  1677. 10 S=10
  1678. 20 T=5
  1679. 30 ERROR S+T
  1680. 40 END
  1681. Ok
  1682. RUN
  1683. String too long in line 30
  1684. Or, in direct mode:
  1685. Ok
  1686. ERROR 15 (You type this line.)
  1687. String too long (BASIC types this line.)
  1688. Ok
  1689. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-30
  1690. Example 2 .
  1691. .
  1692. .
  1693. 110 ON ERROR GOTO 400
  1694. 120 INPUT "WHAT IS YOUR BET";B
  1695. 130 IF B>5000 THEN ERROR 210
  1696. .
  1697. .
  1698. .
  1699. 400 IF ERR=210 THEN PRINT "HOUSE LIMIT IS $5000"
  1700. 410 IF ERL=130 THEN RESUME 120
  1701. .
  1702. .
  1703. .
  1704. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-31
  1705. 2.21 FIELD
  1706. Format FIELD [#]<file number>,<field width> AS <string variable>.
  1707. Purpose To allocate space for variables in a random file
  1708. buffer.
  1709. Remarks Before a GET statement or PUT statement can be
  1710. executed, a FIELD statement must be executed to
  1711. format the random file buffer.
  1712. <file number> is the number under which the file
  1713. was OPENed. <field width> is the number of
  1714. characters to be allocated to <string variable>.
  1715. For example,
  1716. FIELD 1,20 AS N$,10 AS ID$,40 AS ADD$
  1717. allocates the first 20 positions (bytes) in the
  1718. random file buffer to the string variable N$,
  1719. the next 10 positions to ID$, and the next 40
  1720. positions to ADD$. FIELD does NOT place any
  1721. data in the random file buffer. (See
  1722. "LSET/RSET," Section 2.37, and "GET," Section
  1723. 2.23.)
  1724. The total number of bytes allocated in a FIELD
  1725. statement must not exceed the record length that
  1726. was specified when the file was OPENed.
  1727. Otherwise, a "Field overflow" error occurs.
  1728. (The default record length is 128 bytes.)
  1729. Any number of FIELD statements may be executed
  1730. for the same file. All FIELD statements that
  1731. have been executed will remain in effect at the
  1732. same time.
  1733. Note Do not use a FIELDed variable name in an INPUT
  1734. or LET statement. Once a variable name is
  1735. FIELDed, it points to the correct place in the
  1736. random file buffer. If a subsequent INPUT or
  1737. LET statement with that variable name is
  1738. executed, the variable's pointer is moved to
  1739. string space.
  1740. Example 1 FIELD 1,20 AS N$,10 AS ID$,40 AS ADD$
  1741. Allocates the first 20 positions (bytes) in the
  1742. random file buffer to the string variable N$,
  1743. the next 10 positions to ID$, and the next 40
  1744. positions to ADD$. FIELD does NOT place any
  1745. data in the random file buffer. (See also
  1746. "GET," Section 2.23, and "LSET/RSET," Section
  1747. 2.37.)
  1748. MICROSOFT BASICCOMMANDS AND STATEMENTS Page 2-32
  1749. Example 2 10 OPEN "R,"#1,"A:PHONELST",35
  1750. 15 FIELD #1,2 AS RECNBR$,33 AS DUMMY$
  1751. 20 FIELD #1,25 AS NAMES,10 AS PHONENBR$
  1752. 25 GET #1
  1753. 30 TOTAL=CVI(RECNBR)$
  1754. 35 FOR 1=2 TO TOTAL
  1755. 40 GET #1, I
  1756. 45 PRINT NAMES, PHONENBR$
  1757. 50 NEXT I
  1758. Illustrates a multiple defined FIELD statement.
  1759. In statement 15, the 35 byte field is defined
  1760. for the first record to keep track of the number
  1761. of records in the file. In the next loop of
  1762. statements (35-50), statement 20 defines the
  1763. field for individual names and phone numbers.
  1764. Example 3 10 FOR LOOP%=0 TO 7
  1765. 20 FIELD #1,(LOOP%*16) AS OFFSETS,16 AS
  1766. A$(LOOP%)
  1767. 30 NEXT LOOP%
  1768. Shows the construction of a FIELD statement
  1769. using an array of elements of equal size. The
  1770. result is equivalent to the single declaration:
  1771. FIELD #1,16 AS A$(0),16 AS A$(1),...,16 AS
  1772. A$(6),16 AS A$(7)
  1773. Example 4 10 DIM SIZE% (NUMB%): REM ARRAY OF FIELD SIZES
  1774. 20 FOR LOOP%=0 TO NUMB%:READ SIZE%
  1775. (LOOP%): NEXT LOOP%
  1776. 30 DATA 9,10,12,21,41
  1777. .
  1778. .
  1779. .
  1780. 120 DIM A$(NUMB%): REM ARRAY OF FIELDED
  1781. VARIABLES
  1782. 130 OFFSET%=0
  1783. 140 FOR LOOP%=0 TO NUMB%
  1784. 150 FIELD #1,OFFSET% AS OFFSET$,SIZE%(LOOP%)
  1785. AS A$(LOOP%)
  1786. 160 OFFSET%=OFFSET%+SIZE%(LOOP%)
  1787. 170 NEXT LOOP%
  1788. Creates a field in the same manner as Example 3.
  1789. However, the element size varies with each
  1790. element. The equivalent declaration is
  1791. FIELD 41,SIZE%(0) AS A$(0),SIZE%(1) AS A$(1),...
  1792. SIZE%(NUMB%) AS A$(NUMB%)
  1793. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-33
  1794. 2.22 FOR...NEXT
  1795. Format FOR <variable>=x TO y [STEP z]
  1796. NEXT [<variable>][,<variable>...]
  1797. where x, y, and z are numeric expressions.
  1798. Purpose To allow a series of instructions to be
  1799. performed in a loop a given number of times.
  1800. Remarks <variable> is used as a counter. The first
  1801. numeric expression (x) is the initial value of
  1802. the counter. The second numeric expression (y)
  1803. is the final value of the counter. The program
  1804. lines following the FOR statement are executed
  1805. until the NEXT statement is encountered. Then
  1806. the counter is adjusted by the amount specified
  1807. by STEP. A check is performed to see if the
  1808. value of the counter is now greater than the
  1809. final value (y) . If it is not greater,
  1810. Microsoft BASIC branches back to the statement
  1811. after the FOR statement and the process is
  1812. repeated. If it is greater, execution continues
  1813. with the statement following the NEXT statement.
  1814. This is a FOR...NEXT loop.
  1815. If STEP is not specified, the increment is
  1816. assumed to be one. If STEP is negative, the
  1817. final value of the counter is set to be less
  1818. than the initial value. The counter is
  1819. decreased each time through the loop. The loop
  1820. is executed until the counter is less than the
  1821. final value.
  1822. The counter must be an integer or single
  1823. precision numeric constant. If a double
  1824. precision numeric constant is used, a "Type
  1825. mismatch" error will result.
  1826. The body of the loop is skipped if the initial
  1827. value of the loop times the sign of the STEP
  1828. exceeds the final value times the sign of the
  1829. STEP.
  1830. Nested Loons
  1831. FOR...NEXT loops may be nested; that is, a
  1832. FOR...NEXT loop may be placed within the context
  1833. of another FOR...NEXT loop. When loops are
  1834. nested, each loop must have a unique variable
  1835. name as its counter. The NEXT statement for the
  1836. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-34
  1837. inside loop must appear before that for the
  1838. outside loop. If nested loops have the same end
  1839. point, a single NEXT statement may be used for
  1840. all of them.
  1841. The variable(s) in the NEXT statement may be
  1842. omitted, in which case the NEXT statement will
  1843. match the most recent FOR statement. If a NEXT
  1844. statement is encountered before its
  1845. corresponding FOR statement, a "NEXT without
  1846. FOR" error message is issued and execution is
  1847. terminated.
  1848. Example 1
  1849. 10 K=10
  1850. 20 FOR I=1 TO K STEP 2
  1851. 30 PRINT I;
  1852. 40 K=K+10
  1853. 50 PRINT K
  1854. 60 NEXT
  1855. RUN
  1856. 1 20
  1857. 3 30
  1858. 5 40
  1859. 7 50
  1860. 9 60
  1861. Ok
  1862. Example 2
  1863. 10 J=0
  1864. 20 FOR I=1 TO J
  1865. 30 PRINT I
  1866. 40 NEXT I
  1867. In this example, the loop does not execute
  1868. because the initial value of the loop exceeds
  1869. the final value.
  1870. Example 3
  1871. 10 I=5
  1872. 20 FOR I=1 TO I+5
  1873. 30 PRINT I;
  1874. 40 NEXT
  1875. RUN
  1876. 1 2 3 4 5 6 7 8 9 10
  1877. Ok
  1878. In this example, the loop executes ten times.
  1879. The final value for the loop variable is always
  1880. set before the initial value is set.
  1881. Note Previous versions of Microsoft BASIC set the
  1882. initial value of the loop variable before
  1883. setting the final value; i.e., the above loop
  1884. would have executed six times.
  1885. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-35
  1886. 2.23 GET
  1887. Format GET [#]<file number>[,<record number>]
  1888. Purpose To read a record from a random disk file into a
  1889. random buffer.
  1890. Remarks <file number> is the number under which the file
  1891. was OPENed. If <record number> is omitted, the
  1892. next record (after the last GET) is read into
  1893. the buffer. The largest possible record number
  1894. is 32767.
  1895. Example See "Microsoft BASIC Disk I/O," in the Microsoft
  1896. BASIC User's Guide.
  1897. Note After a GET statement has been executed, INPUT#
  1898. and LINE ENPUT# may be executed to read
  1899. characters from the random file buffer.
  1900. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-36
  1901. 2.24 GOSUB...RETURN
  1902. Format GOSUB <line number>
  1903. .
  1904. .
  1905. .
  1906. RETURN
  1907. Purpose To branch to and return from a subroutine.
  1908. Remarks <line number> is the first line of the
  1909. subroutine.
  1910. A subroutine may be called any number of times
  1911. in a program. A subroutine also may be called
  1912. from within another subroutine. Such nesting of
  1913. subroutines is limited only by available memory.
  1914. The RETURN statement(s) in a subroutine cause
  1915. Microsoft BASIC to branch back to the statement
  1916. following the most recent GOSUB statement. A
  1917. subroutine may contain more than one RETURN
  1918. statement, should logic dictate a return at
  1919. different points in the subroutine. Subroutines
  1920. may appear anywhere in the program, but it is
  1921. recommended that the subroutine be readily
  1922. distinguishable from the main program. To
  1923. prevent inadvertent entry into the subroutine,
  1924. precede it with a STOP, END, or GOTO statement
  1925. that directs program control around the
  1926. subroutine.
  1927. Example 10 GOSUB 40
  1928. 20 PRINT "BACK FROM SUBROUTINE"
  1929. 30 END
  1930. 40 PRINT "SUBROUTINE";
  1931. 50 PRINT " IN";
  1932. 60 PRINT " PROGRESS"
  1933. 70 RETURN
  1934. RUN
  1935. SUBROUTINE IN PROGRESS
  1936. BACK FROM SUBROUTINE
  1937. Ok
  1938. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-37
  1939. 2.25 GOTO
  1940. Format GOTO <line number>
  1941. Purpose To branch unconditionally out of the normal
  1942. program sequence to a specified line number.
  1943. Remarks If <line number> is an executable statement,
  1944. that statement and those following are executed.
  1945. If it is a nonexecutable statement, execution
  1946. proceeds at the first executable statement
  1947. encountered after <line number>.
  1948. Example LIST
  1949. 10 READ R
  1950. 20 PRINT "R =";R,
  1951. 30 A=3.14*R^2
  1952. 40 PRINT"AREA =";A
  1953. 50 GOTO 10
  1954. 60 DATA 5,7,12
  1955. Ok
  1956. RUN
  1957. R = 5 AREA =78.5
  1958. R = 7 AREA =153.86
  1959. R = 12 AREA =452.16
  1960. ?Out ofdata in 10
  1961. Ok
  1962. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-38
  1963. 2.26 IF...THEN [...ELSE] AND IF...GOTO
  1964. Format IF <expression> THEN {<statement(s)>|<line number>}
  1965. [ELSE {<statement(s)>|<line number>}]
  1966. Format IF <expression> GOTO <line number>
  1967. [ELSE {statement(s)>|<Iine number>}]
  1968. Purpose To make a decision regarding program flow based
  1969. on the result returned by an expression.
  1970. Remarks If the result of <expression> is not zero, the
  1971. THEN or GOTO clause is executed. THEN may be
  1972. followed by either a line number for branching
  1973. or one or more statements to be executed. GOTO
  1974. is always followed by a line number. If the
  1975. result of <expression> is zero, the THEN or GOTO
  1976. clause is ignored and the ELSE clause, if
  1977. present, is executed. Execution continues with
  1978. the next executable statement. A comma is
  1979. allowed before THEN.
  1980. Nesting of IF Statements
  1981. IF...THEN...ELSE statements may be nested.
  1982. Nesting is limited only by the length of the
  1983. line. For example,
  1984. IF X>Y THEN PRINT "GREATER" ELSE IF Y>X
  1985. THEN PRINT "LESS THAN" ELSE PRINT "EQUAL"
  1986. is a legal statement. If the statement does not
  1987. contain the same number of ELSE and THEN
  1988. clauses, each ELSE is matched with the closest
  1989. unmatched THEN. For example
  1990. IF A=B THEN IF B=C THEN PRINT "A=C"
  1991. ELSE PRINT "A<>C"
  1992. will not print "A<>C" when A<>B.
  1993. If an IF...THEN statement is followed by a line
  1994. number in direct mode, an "Undefined line" error
  1995. results, unless a statement with the specified
  1996. line number had previously been entered in
  1997. indirect mode.
  1998. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-39
  1999. Note When using IF to test equality for a value that
  2000. is the result of a floating-point computation,
  2001. remember that the internal representation of the
  2002. value may not be exact. Therefore, the test
  2003. should be against the range over which the
  2004. accuracy of the value may vary. For example, to
  2005. test a computed variable A against the value
  2006. 1.0, use:
  2007. IF ABS (A-1.0)<1.0E-6 THEN ...
  2008. This test returns true if the value of A is 1.0
  2009. with a relative error of less than 1.0E-6.
  2010. Example 1 200 IF I THEN GET#1,I
  2011. This statement GETS record number I if I is not
  2012. zero.
  2013. Example 2 100 IF(I<20)*(I>10) THEN DB=1979-1:GOTO 300
  2014. 110 PRINT "OUT OF RANGE"
  2015. .
  2016. .
  2017. .
  2018. In this example, a test determines if I is
  2019. greater than 10 and less than 20. If I is in
  2020. this range, DB is calculated and execution
  2021. branches to line 300. If I is not in this
  2022. range, execution continues with line 110.
  2023. Example 3 210 IF IOFLAG THEN PRINT A$ ELSE LPRINT A$
  2024. This statement causes printed output to go
  2025. either to the terminal or the line printer,
  2026. depending on the value of the variable IOFLAG.
  2027. If IOFLAG is zero, output goes to the line
  2028. printer; otherwise, output goes to the
  2029. terminal.
  2030. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-40
  2031. 2.27 INPUT
  2032. Format INPUT[;] [<"prompt string">;]<list of variables>
  2033. Purpose To allow input from the terminal during program
  2034. execution.
  2035. Remarks When an INPUT statement is encountered, program
  2036. execution pauses and a question mark is printed
  2037. to indicate the program is waiting for data. If
  2038. <"prompt string"> is included, the string is
  2039. printed before the question mark. The required
  2040. data is then entered at the terminal.
  2041. A comma may be used instead of a semicolon after
  2042. the prompt string to suppress the question mark.
  2043. For example, the statement INPUT "ENTER
  2044. BIRTHDATE",B$ will print the prompt with no
  2045. question mark.
  2046. If INPUT is immediately followed by a semicolon,
  2047. then the carriage return typed by the user to
  2048. input data does not echo a carriage return/line
  2049. feed sequence.
  2050. The data that is entered is assigned to the
  2051. variable(s) given in <variable list>. The
  2052. number of data items supplied must be the same
  2053. as the number of variables in the list. Data
  2054. items are separated by commas.
  2055. The variable names in the list may be numeric or
  2056. string variable names (including subscripted
  2057. variables). The type of each data item that is
  2058. input must agree with the type specified by the
  2059. variable name. (Strings input to an INPUT
  2060. statement need not be surrounded by quotation
  2061. marks.)
  2062. Responding to INPUT with too many or too few
  2063. items or with the wrong type of value (numeric
  2064. instead of string, etc.) causes the messsage
  2065. "?Redo from start" to be printed. No assignment
  2066. of input values is made until an acceptable
  2067. response is given.
  2068. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-41
  2069. Examples 10 INPUT X
  2070. 20 PRINT X "SQUARED IS" X^2
  2071. 30 END
  2072. RUN
  2073. ? 5 (The 5 was typed in by the user
  2074. in response to the question mark.)
  2075. 5 SQUARED IS 25
  2076. Ok
  2077. LIST
  2078. 10 PI=3.14
  2079. 20 INPUT "WHAT IS THE RADIUS";R
  2080. 30 A=PI*R^a2
  2081. 40 PRINT "THE AREA OF THE CIRCLE IS" ;A
  2082. 50 PRINT
  2083. 60 GOTO 20
  2084. Ok
  2085. RUN
  2086. WHAT IS THE RADIUS? 7.4 (User types 7.4)
  2087. THE AREA OF THE CIRCLE IS 171.946
  2088. WHAT IS THE RADIUS?
  2089. etc.
  2090. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-42
  2091. 2.28 INPUT#
  2092. Format INPUT#<fi1e number>,<variable list>
  2093. Purpose To read data items from a sequential disk file
  2094. and assign them to program variables.
  2095. Remarks <file number> is the number used when the file
  2096. was OPENed for input. <variable list> contains
  2097. the variable names that will be assigned to the
  2098. items in the file. (The variable type must
  2099. match the type specified by the variable name.)
  2100. With INPUT#, no question mark is printed, as
  2101. with INPUT.
  2102. The data items in the file should appear just as
  2103. they would if data were being typed in response
  2104. to an INPUT statement. With numeric values,
  2105. leading spaces, carriage returns, and line feeds
  2106. are ignored. The first character encountered
  2107. that is not a space, carriage return, or line
  2108. feed is assumed to be the start of a number.
  2109. The number terminates on a space, carriage
  2110. return, line feed, or comma.
  2111. If Microsoft BASIC is scanning the sequential
  2112. data file for a string item, leading spaces,
  2113. carriage returns, and line feeds are also
  2114. ignored. The first character encountered that
  2115. is not a space, carriage return, or line feed is
  2116. assumed to be the start of a string item. If
  2117. this first character is a quotation mark ("),
  2118. the string item will consist of all characters
  2119. read between the first quotation mark and the
  2120. second. Thus, a quoted string may not contain a
  2121. quotation mark as a character. If the first
  2122. character of the string is not a quotation mark,
  2123. the string is an unquoted string, and will
  2124. terminate on a comma, carriage return, or line
  2125. feed (or after 255 characters have been read).
  2126. If end-of-file is reached when a numeric or
  2127. string item is being INPUT, the item is
  2128. terminated.
  2129. Example See "Microsoft BASIC Disk I/0," in the Microsoft
  2130. BASIC User's Guide.
  2131. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-43
  2132. 2.29 KILL
  2133. Format KILL <filename>
  2134. Purpose To delete a file from disk.
  2135. Remarks If a KILL statement is given for a file that is
  2136. currently OPEN, a "File already open" error
  2137. occurs.
  2138. KILL is used for all types of disk files;
  2139. program files, random data files, and sequential
  2140. data files.
  2141. Example 200 KILL "DATAl.DAT"
  2142. See also "Microsoft BASIC Disk I/O," in the
  2143. Microsoft BASIC User's Guide.
  2144. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-44
  2145. 2.30 LET
  2146. Format [LET ]<variable>=<expression>
  2147. Purpose To assign the value of an expression to a
  2148. variable.
  2149. Remarks Notice the word LET is optional; i.e., the
  2150. equal sign is sufficient for assigning an
  2151. expression to a variable name.
  2152. Example 110 LET D=12
  2153. 120 LET E=12^2
  2154. 130 LET F=12^4
  2155. 140 LET SUM=D+E+F
  2156. .
  2157. .
  2158. .
  2159. or
  2160. 110 D=12
  2161. 120 E=12^2
  2162. 130 F=12^4
  2163. 140 SUM=D+E+F
  2164. .
  2165. .
  2166. .
  2167. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-45
  2168. 2.31 LINE INPUT
  2169. Format LINE INPUT[;] [<"prompt string">;]<string variable>
  2170. Purpose To input an entire line (up to 254 characters)
  2171. to a string variable, without the use of
  2172. delimiters.
  2173. Remarks <"prompt string"> is a string literal that is
  2174. printed at the terminal before input is
  2175. accepted. A question mark is not printed unless
  2176. it is part of <"prompt string">. All input from
  2177. the end of <"prompt string"> to the carriage
  2178. return is assigned to <string variable>.
  2179. However, if a line feed/carriage return sequence
  2180. (this order only) is encountered, both
  2181. characters are echoed; but the carriage return
  2182. is ignored, the line feed is put into <string
  2183. variable>, and data input continues.
  2184. If LINE INPUT is immediately followed by a
  2185. semicolon, then the carriage return typed by the
  2186. user to end the input line does not echo a
  2187. carriage return/line feed sequence at the
  2188. terminal.
  2189. A LINE INPUT statement may be aborted by typing
  2190. Control-C. Microsoft BASIC will return to
  2191. command level and type "Ok". Typing CONT
  2192. resumes execution at the LINE INPUT.
  2193. Example See "LINE INPUT#," Section 2.32.
  2194. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-46
  2195. 2.32 LINE INPUT#
  2196. Format LINE INPUT#<file number>,<string variable>
  2197. Purpose To read an entire line (up to 254 characters),
  2198. without delimiters, from a sequential disk data
  2199. file to a string variable.
  2200. Remarks <file number> is the number under which the file
  2201. was OPENed. <string variable> is the variable
  2202. name to which the line will be assigned. LINE
  2203. INPUT# reads all characters in the sequential
  2204. file up to a carriage return. It then skips
  2205. over the carriage return/line feed sequence.
  2206. The next LINE INPUT# reads all characters up to
  2207. the next carriage return. (If a line
  2208. feed/carriage return sequence is encountered, it
  2209. is preserved.)
  2210. LINE INPUT# is especially useful if each line of
  2211. a data file has been broken into fields, or if a
  2212. Microsoft BASIC program saved in ASCII format is
  2213. being read as data by another program. (See
  2214. "SAVE," Section 2.60.)
  2215. Example 10 OPEN "0",1,"LIST"
  2216. 20 LINE INPUT "CUSTOMER INFORMATION? ";C$
  2217. 30 PRINT #1, C$
  2218. 40 CLOSE 1
  2219. 50 OPEN "I",1,"LIST"
  2220. 60 LINE INPUT #1, C$
  2221. 70 PRINT C$
  2222. 80 CLOSE 1
  2223. RUN
  2224. CUSTOMER INFORMATION? LINDA JONES 234,4 MEMPHIS
  2225. LINDA JONES 234,4 MEMPHIS
  2226. Ok
  2227. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-47
  2228. 2.33 LIST
  2229. Format 1 LIST[ <line number>]
  2230. Format 2 LIST [<line number>] [-[<line number>]]
  2231. Purpose To list all or part of the program currently in
  2232. memory at the terminal.
  2233. Remarks Microsoft BASIC always returns to command level
  2234. after a LIST is executed.
  2235. Format 1
  2236. If <line number> is omitted, the program is
  2237. listed beginning at the lowest line number.
  2238. (Listing is terminated either when the end of
  2239. the program is reached or by typing Control-C.)
  2240. If <line number> is included, only the specified
  2241. line will be listed.
  2242. Format 2
  2243. This format allows the following options:
  2244. 1. If only the first <line number> is
  2245. specified, that line and all higher-numbered
  2246. lines are listed.
  2247. 2. If only the second <line number> (i.e.,
  2248. [-[<line number>]]) is specified, all lines
  2249. from the beginning of the program through
  2250. that line are listed.
  2251. 3. If both <line number(s)> are specified, the
  2252. entire range is listed.
  2253. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-48
  2254. Examples Format 1
  2255. LIST Lists the program currently
  2256. in memory.
  2257. LIST 500 Lists line 500.
  2258. Format 2
  2259. LIST 150- Lists all lines from 150
  2260. to the end.
  2261. LIST -1000 Lists all lines from the
  2262. lowest number through 1000.
  2263. LIST 150-1000 Lists lines 150 through
  2264. 1000, inclusive.
  2265. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-49
  2266. 2.34 LLIST
  2267. Format LLIST [<line number>[-[<line number>]]]
  2268. Purpose To list all or part of the program currently in
  2269. memory at the line printer.
  2270. Remarks LLIST assumes a 132-character-wide printer.
  2271. Microsoft BASIC always returns to command level
  2272. after an LLIST is executed. The options for
  2273. LLIST are the same as for LIST, Format 2.
  2274. Note LLIST and LPRINT are not included in all
  2275. implementations of Microsoft BASIC.
  2276. Example See the examples for "LIST," Format 2.
  2277. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-50
  2278. 2.35 LOAD
  2279. Format LOAD <filename>[,R]
  2280. Purpose To load a file from disk into memory.
  2281. Remarks <filename> is the name that was used when the
  2282. file was SAVEd. (Your operating system may
  2283. append a default filename extension if one was
  2284. not supplied in the SAVE command. Refer to
  2285. "Microsoft BASIC Disk I/O," in the Microsoft
  2286. BASIC User's Guide, for information about
  2287. possible filename extensions your operating
  2288. system.)
  2289. The R option automatically runs the program
  2290. after it has been loaded.
  2291. LOAD closes all open files and deletes all
  2292. variables and program lines currently residing
  2293. in memory before it loads the designated
  2294. program. However, if the R option is used with
  2295. LOAD, the program is RUN after it is LOADed, and
  2296. all open data files are kept open. Thus, LOAD
  2297. with the R option may be used to chain several
  2298. programs (or segments of the same program).
  2299. Information may be passed between the programs
  2300. using their disk data files.
  2301. Example LOAD "STRTRK",R
  2302. LOAD "B:MYPROG"
  2303. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-51
  2304. 2.36 LPRINT AND LPRINT USING
  2305. Format LPRINT [<list of expressions>]
  2306. LPRINT USING <string exp>;<list of expressions>
  2307. Purpose To print data at the line printer.
  2308. Remarks Same as PRINT and PRINT USING, except output
  2309. goes to the line printer. See Section 2.49 and
  2310. Section 2.50.
  2311. LPRINT assumes a 132-character-wide printer.
  2312. Note LPRINT and LLIST are not included in all
  2313. implementations of Microsoft BASIC.
  2314. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-52
  2315. 2.37 LSET AND RSET
  2316. Format LSET <string variable>=<string expression>
  2317. RSET <string variable>=<string expression>
  2318. Purpose To move data from memory to a random file buffer
  2319. (in preparation for a PUT statement).
  2320. Remarks If <string expression> requires fewer bytes than
  2321. were FIELDed to <string variable>, LSET
  2322. left-justifies the string in the field, and RSET
  2323. right-justifies the string. (Spaces are used to
  2324. pad the extra positions.) If the string is too
  2325. long for the field, characters are dropped from
  2326. the right. Numeric values must be converted to
  2327. strings before they are LSET or RSET. See
  2328. "MKI$, MKS$, MKDS," Section 3.26.
  2329. Examples 150 LSET A$=MKS$(AMT)
  2330. 160 LSET D$=DESC($)
  2331. See also "Microsoft BASIC Disk I/0,"
  2332. in the Microsoft BASIC User's Guide.
  2333. Note LSET or RSET may also be used with a nonfielded
  2334. string variable to left-justify or right-justify
  2335. a string in a given field. For example, the
  2336. program lines
  2337. 110 A$=SPACE$(20)
  2338. 120 RSET A$=N$
  2339. right-justify the string N$ in a 20-character
  2340. field. This can be very handy for formatting
  2341. printed output.
  2342. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-53
  2343. 2.38 MERGE
  2344. Format MERGE <filename>
  2345. Purpose To merge a specified disk file into the program
  2346. currently in memory.
  2347. Remarks <filename> is the name used when the file was
  2348. SAVEd. (Your operating system may append a
  2349. default filename extension if one was not
  2350. supplied in the SAVE command. Refer to
  2351. "Microsoft BASIC Disk I/O," in the Microsoft
  2352. BASIC User's Guide, for information about
  2353. possible filename extensions under your
  2354. operating system.) The file must have been SAVEd
  2355. in ASCII format. (If not, a "Bad file mode"
  2356. error occurs.)
  2357. If any lines in the disk file have the same line
  2358. numbers as lines in the program in memory, the
  2359. lines from the file on disk will replace the
  2360. corresponding lines in memory. (MERGEing may be
  2361. thought of as "inserting" the program lines on
  2362. disk into the program in memory.)
  2363. Microsoft BASIC always returns to command level
  2364. after executing a MERGE command.
  2365. Example MERGE "NUMBRS"
  2366. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-54
  2367. 2.39 MID$
  2368. Format MID$(<string exp1>,n[,m])=<string exp2>
  2369. where n and m are integer expressions and
  2370. <string exp1> and <string exp2> are string
  2371. expressions.
  2372. Purpose To replace a portion of one string with another
  2373. string.
  2374. Remarks The characters in <string exp1>, beginning at
  2375. position n, are replaced by the characters in
  2376. <string exp2>. The optional "m" refers to the
  2377. number of characters from <string exp2> that
  2378. will be used in the replacement. If "m" is
  2379. omitted, all of <string exp2> is used. However,
  2380. regardless of whether "m" is omitted or
  2381. included, the replacement of characters never
  2382. goes beyond the original length of <string
  2383. exp1>.
  2384. Example 10 A$="KANSAS CITY, MO"
  2385. 20 MID$(A$,14)="KS"
  2386. 30 PRINT A$
  2387. RUN
  2388. KANSAS CITY, KS
  2389. MID$ is also a function that returns a substring
  2390. of a given string. See Section 3.25.
  2391. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-55
  2392. 2.40 NAME
  2393. Format NAME <old filename> AS <new filename>
  2394. Purpose To change the name of a disk file.
  2395. Remarks <old filename> must exist and <new filename>
  2396. must not exist; otherwise, an error will
  2397. result. After a NAME command, the file exists
  2398. on the same disk, in the same area of disk
  2399. space, with the new name.
  2400. Example Ok
  2401. NAME "ACCTS" AS "LEDGER"
  2402. Ok
  2403. In this example, the file that was
  2404. formerly named ACCTS will now be named LEDGER.
  2405. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-56
  2406. 2.41 NEW
  2407. Format NEW
  2408. Purpose To delete the program currently in memory and
  2409. clear all variables.
  2410. Remarks NEW is entered at command level to clear memory
  2411. before entering a new program. Microsoft BASIC
  2412. always returns to command level after a NEW is
  2413. executed.
  2414. Example NEW
  2415. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-57
  2416. 2.42 NULL
  2417. Format NULL <integer expression>
  2418. Purpose To set the number of nulls to be printed at the
  2419. end of each line.
  2420. Remarks For 10 character-per-second tape punches,
  2421. <integer expression> should be >=3. When tapes
  2422. are not being punched, <integer expression>
  2423. should be 0 or I for Teletype(R) and
  2424. Teletype-compatible terminal screens. <integer
  2425. expression> should be 2 or 3 for 30 CPS hard
  2426. copy printers. The default value is 0.
  2427. Example Ok
  2428. NULL 2
  2429. Ok
  2430. 100 INPUT X
  2431. 200 IF X<50 GOTO 800
  2432. .
  2433. .
  2434. .
  2435. Two null characters will be printed after each
  2436. line.
  2437. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-58
  2438. 2.43 ON ERROR GOTO
  2439. Format ON ERROR GOTO <line number>
  2440. Purpose To enable error handling and specify the first
  2441. line of the error handling routine.
  2442. Remarks Once error handling has been enabled, all errors
  2443. detected, including direct mode errors (e.g.,
  2444. syntax errors), will cause a jump to the
  2445. specified error handling routine. If <line
  2446. number> does not exist, an "Undefined line"
  2447. error results.
  2448. To disable error handling, execute an ON ERROR
  2449. GOTO 0. Subsequent errors will print an error
  2450. message and halt execution. An ON ERROR GOTO 0
  2451. statement that appears in an error handling
  2452. routine causes Microsoft BASIC to stop and print
  2453. the error message for the error that caused the
  2454. trap. It is recommended that all error handling
  2455. routines execute an ON ERROR GOTO 0 if an error
  2456. is encountered for which there is no recovery
  2457. action.
  2458. Note If an error occurs during execution of an error
  2459. handling routine, that error message is printed
  2460. and execution terminates. Error trapping does
  2461. not occur within the error handling routine.
  2462. Example 10 ON ERROR GOTO 1000
  2463. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-59
  2464. 2.44 ON...GOSUB AND ON...GOTO
  2465. Format ON <expression> GOTO <list of line numbers>
  2466. ON <expression> GOSUB <list of line numbers>
  2467. Purpose To branch to one of several specified line
  2468. numbers, depending on the value returned when an
  2469. expression is evaluated.
  2470. Remarks The value of <expression> determines which line
  2471. number in the list will be used for branching.
  2472. For example, if the value is three, the third
  2473. line number in the list will be the destination
  2474. of the branch. (If the value is a noninteger,
  2475. the fractional portion is rounded.)
  2476. In the ON...GOSUB statement, each line number in
  2477. the list must be the first line number of a
  2478. subroutine.
  2479. If the value of <expression> is zero or greater
  2480. than the number of items in the list (but less
  2481. than or equal to 255), Microsoft BASIC continues
  2482. with the next executable statement. If the
  2483. value of <expression> is negative or greater
  2484. than 255, an "Illegal function call" error
  2485. occurs.
  2486. Example 100 ON L-1 GOTO 150,300,320,390
  2487. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-60
  2488. 2.45 OPEN
  2489. Format OPEN <mode>,[#]<file number>,<filename>[,<reclen>]
  2490. Purpose To allow I/O to a disk file.
  2491. Remarks A disk file must be OPENed before any disk I/O
  2492. operation can be performed on that file. OPEN
  2493. allocates a buffer for I/O to the file and
  2494. determines the mode of access that will be used
  2495. with the buffer.
  2496. <mode> is a strinc expression whose first
  2497. character is one of the following:
  2498. 0 Specifies sequential output mode.
  2499. I Specifies sequential input mode.
  2500. R Specifies random input/output mode.
  2501. <file number> is an integer expression whose
  2502. value is between 1 and 15. The number is then
  2503. associated with the file for as long as it is
  2504. OPEN and is used to refer other disk I/O
  2505. statements to the file.
  2506. <filename> is a string expression containing a
  2507. name that conforms to your operating system's
  2508. rules for disk filenames.
  2509. <reclen> is an integer expression which, if
  2510. included, sets the record length for random
  2511. files. The default record length is 128 bytes.
  2512. Note A file can be OPENed for sequential input or
  2513. random access on more than one file number at a
  2514. time. A file may be OPENed for output, however,
  2515. on only one file number at a time.
  2516. Example 10 OPEN "I",2,"INVEN"
  2517. See also "Microsoft BASIC Disk I/O," in the
  2518. Microsoft BASIC User's Guide.
  2519. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-61
  2520. 2.46 OPTION BASE
  2521. Format OPTION BASE n
  2522. where n is 1 or 0
  2523. Purpose To declare the minimum value for array
  2524. subscripts.
  2525. Remarks The default base is 0. If the statement
  2526. OPTION BASE 1
  2527. is executed, the lowest value an array subscript
  2528. may have is 1.
  2529. Example OPTION BASE 1
  2530. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-62
  2531. 2.47 OUT
  2532. Format OUT I,J
  2533. where I and J. are integer expressions in the
  2534. range 0 to 255.
  2535. Purpose To send a byte to a machine output port.
  2536. Remarks The integer expression I is the port number.
  2537. The integer expression J is the data to be
  2538. transmitted.
  2539. Example 100 OUT 32,100
  2540. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-63
  2541. 2.48 POKE
  2542. Format POKE I,J
  2543. where I and J are integer expressions.
  2544. Purpose To write a byte into a memory location.
  2545. Remarks I and J are integer expressions. The expression
  2546. I represents the address of the memory location
  2547. and J is the data byte. I must be in the range
  2548. -32768 to 65535. (For interpretation of
  2549. negative values of I, see "VARPTR," Section
  2550. 3.43.)
  2551. The complementary function to POKE is PEEK. The
  2552. argument to PEEK is an address from which a byte
  2553. is to be read. See Section 3.28.
  2554. POKE and PEEK are useful for storing data
  2555. efficiently, loading assembly language
  2556. subroutines, and passing arguments and results
  2557. to and from assembly language subroutines.
  2558. Example 10 POKE &H5A00,&HFF
  2559. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-64
  2560. 2.49 PRINT
  2561. Format PRINT [<list of expressions>]
  2562. Purpose To output data at the terminal.
  2563. Remarks If <list of expressions> is omitted, a blank
  2564. line is printed. If <list of expressions> is
  2565. included, the values of the expressions are
  2566. printed at the terminal. The expressions in the
  2567. list may be numeric and/or string expressions.
  2568. (Strings must be enclosed in quotation marks.)
  2569. Print Positions
  2570. The position of each printed item is determined
  2571. by the punctuation used to separate the items in
  2572. the list. Microsoft BASIC divides the line into
  2573. print zones of 14 spaces each. In the list of
  2574. expressions, a comma causes the next value to be
  2575. printed at the beginning of the next zone. A
  2576. semicolon causes the next value to be printed
  2577. immediately after the last value. Typing one or
  2578. more spaces between expressions has the same
  2579. effect as typing a semicolon.
  2580. If a comma or a semicolon terminates the list of
  2581. expressions, the next PRINT statement begins
  2582. printing on the same line, spacing accordingly.
  2583. If the list of expressions terminates without a
  2584. comma or a semicolon, a carriage return is
  2585. printed at the end of the line. If the printed
  2586. line is longer than the terminal width,
  2587. Microsoft BASIC goes to the next physical line
  2588. and continues printing.
  2589. Printed numbers are always followed by a space.
  2590. Positive numbers are preceded by a space.
  2591. Negative numbers are preceded by a minus sign.
  2592. Single precision numbers that can be represented
  2593. with 6 or fewer digits in the unscaled format no
  2594. less accurately than they can be represented in
  2595. the scaled format, are output using the unscaled
  2596. format. For example, 1E-7 is output as .0000001
  2597. and 1E-8(-7) is output as 1E-08. Double
  2598. precision numbers that can be represented with
  2599. 16 or fewer digits in the unscaled format no
  2600. less accurately than they can be represented in
  2601. the scaled format, are output using the unscaled
  2602. format. For example, 1D-15 is output as
  2603. .0000000000000001 and 1D-16 is output as ID-16.
  2604. A question mark may be used in place of the word
  2605. PRINT in a PRINT statement.
  2606. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-65
  2607. Example 1 10 X=5
  2608. 20 PRINT X+5,X-5,X*(-5),X^5
  2609. 30 END
  2610. RUN
  2611. 10 0 -25 3125
  2612. Ok
  2613. In this example, the commas in the PRINT
  2614. statement cause each value to be printed at the
  2615. beginning of the next print zone.
  2616. Example 2 LIST
  2617. 10 INPUT X
  2618. 20 PRINT X "SQUARED IS" X^2 "AND";
  2619. 30 PRINT X "CUBED IS" X^3
  2620. 40 PRINT
  2621. 50 GOTO 10
  2622. Ok
  2623. RUN
  2624. ? 9
  2625. 9 SQUARED IS 81 AND 9 CUBED IS 729
  2626. ? 21
  2627. 21 SQUARED IS 441 AND 21 CUBED IS 9261
  2628. In this example, the semicolon at the end of
  2629. line 20 causes both PRINT statements to be
  2630. printed on the same line. Line 40 causes a
  2631. blank line to be printed before the next prompt.
  2632. Example 3 10 FOR X=1 TO 5
  2633. 20 J=J+5
  2634. 30 K=K+10
  2635. 40 ?J;K;
  2636. 50 NEXT X
  2637. Ok
  2638. RUN
  2639. 5 10 10 20 15 30 20 40 25 50
  2640. Ok
  2641. In this example, the semicolons in the PRINT
  2642. statement cause each value to be printed
  2643. immediately after the preceding value. (Don't
  2644. forget, a number is always followed by a space,
  2645. and positive numbers are preceded by a space.)
  2646. In line 40, a question mark is used instead of
  2647. the word PRINT.
  2648. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-66
  2649. 2.50 PRINT USING
  2650. Format PRINT USING <string exp>;<list of expressions>
  2651. Purpose To print strings or numbers using a specified
  2652. format.
  2653. Remarks <list of expressions> is comprised of the string
  2654. and expressions or numeric expressions that are to
  2655. Examples be printed, separated by semicolons. <string
  2656. exp> is a string literal (or variable) composed
  2657. of special formatting characters. These
  2658. formatting characters (see below) determine the
  2659. field and the format of the printed strings or
  2660. numbers.
  2661. String Fields
  2662. When PRINT USING is used to print strings, one
  2663. of three formatting characters may be used to
  2664. format the string field:
  2665. "!"
  2666. Specifies that only the first character in the
  2667. given string is to be printed.
  2668. "\n spaces\"
  2669. Specifies that 2+n characters from the string
  2670. are to be printed. If the backslashes are typed
  2671. with no spaces, two characters will be printed;
  2672. with one space, three characters will be
  2673. printed, and so on. If the string is longer
  2674. than the field, the extra characters are
  2675. ignored. If the field is longer than the
  2676. string, the string will be left-justified. in the
  2677. field and padded with spaces on the right.
  2678. Example:
  2679. 10 A$="LOOK":B$="OUT"
  2680. 30 PRINT USING "!";A$;B$
  2681. 40 PRINT USING "\ \";A$;B$
  2682. 50 PRINT USING "\ \";A$;B$;"!!"
  2683. RUN
  2684. LO
  2685. LOOKOUT
  2686. LOOK OUT !!
  2687. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-67
  2688. "&" Specifies a variable length string field. When
  2689. the field is specified with "&", the string is
  2690. output without modification.
  2691. Example:
  2692. 10 A$="LOOK":B$="OUT"
  2693. 20 PRINT USING "!";A$;
  2694. 30 PRINT USING "&";8$
  2695. RUN
  2696. LOUT
  2697. Numeric Fields
  2698. When PRINT USING is used to print numbers, the
  2699. following special characters may be used to
  2700. format the numeric field:
  2701. # A number sign is used to represent each digit
  2702. position. Digit positions are always filled.
  2703. If the number to be printed has fewer digits
  2704. than positions specified, the number will be
  2705. right-justified (preceded by spaces) in the
  2706. field.
  2707. . A decimal point may be inserted at any position
  2708. in the field. If the format string specifies
  2709. that a digit is to precede the decimal point,
  2710. the digit will always be printed (as 0, if
  2711. necessary). Numbers are rounded as necessary.
  2712. PRINT USING "##.##";.78
  2713. 0.78
  2714. PRINT USING "###.##";987.654
  2715. 987.65
  2716. PRINT USING "##.## ;l0.2,5.3,66.789,.234
  2717. 10.20 5.30 66.79 0.23
  2718. In the last example, three spaces were inserted
  2719. at the end of the format string to separate the
  2720. printed values on the line.
  2721. + A plus sign at the beginning or end of the
  2722. format string will cause the sign of the number
  2723. (plus or minus) to be printed before or after
  2724. the number.
  2725. MICROSOFT BASIC COMmANDS AND STATEMENTS Page 2-68
  2726. - A minus sign at the end of the format field will
  2727. cause negative numbers to be printed with a
  2728. trailing minus sign.
  2729. PRINT USING "+##.## ";-68.95,2.4,55.6,-.9
  2730. -68.95 +2.40 +55.60 -0.90
  2731. PRINT USING "##.##- ";-66.95,22.449,-7.01
  2732. 68.95- 22.45 7.01-
  2733. ** A double asterisk at the beginning of the format
  2734. string causes leading spaces in the numeric
  2735. field to be filled with asterisks. The ** also
  2736. specifies positions for two more digits.
  2737. PRINT USING "**#.# ";12.39,-0.9,765.1
  2738. *12.4 *-0.9 765.1
  2739. $$ A double dollar sign causes a dollar sign to be
  2740. printed to the immediate left of the formatted
  2741. number. The $$ specifies two more digit
  2742. positions, one of which is the dollar sign. The
  2743. exponential format cannot be used with $$.
  2744. Negative numbers cannot be used unless the minus
  2745. sign trails to the right.
  2746. PRINT USING "$$###.##";456.76
  2747. $456.78
  2748. **$ The **$ at the beginning of a format string
  2749. combines the effects of the above two symbols.
  2750. Leading spaces will be asterisk-filled and a
  2751. dollar sign will be printed before the number.
  2752. **$ specifies three more digit positions, one of
  2753. which is the dollar sign.
  2754. PRINT USING "**$##.##";2.34
  2755. ***$2.34
  2756. , A comma that is to the left of the decimal point
  2757. in a formatting string causes a comma to be
  2758. printed to the left of every third digit to the
  2759. left of the decimal point. A comma that is at
  2760. the end of the format string is printed as part
  2761. of the string. A comma specifies another digit
  2762. position. The comma has no effect if used with
  2763. the exponential ( ) format.
  2764. PRINT USING "####,.##";1234.5
  2765. 1,234.50
  2766. PRINT USING "####.##,";1234.5
  2767. 1234.50,
  2768. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-69
  2769. ^^^^ Four carets (or up-arrows) may be placed after
  2770. the digit position characters to specify
  2771. exponential format. The four carets allow space
  2772. for E+xx to be printed. Any decimal point
  2773. position may be specified. The significant
  2774. digits are left-justified, and the exponent is
  2775. adjusted. Unless a leading + or trailing + or -
  2776. is specified, one digit position will be used to
  2777. the left of the decimal point to print a space
  2778. or a minus sign.
  2779. PRINT USING "##.##^^^^" ;234.56
  2780. 2.35E+02
  2781. PRINT USING ".####^^^^-";888888
  2782. .8889E+06
  2783. PRINT USING "+.##^^^^";123
  2784. +.12E+03
  2785. _ An underscore in the format string causes the
  2786. next character to be output as a literal
  2787. character.
  2788. PRINT USING "_!##.## !";12.34
  2789. !12.34!
  2790. The literal character itself may be an
  2791. underscore by placing "__" in the format string.
  2792. % If the number to be Printed is larger than the
  2793. specified numeric field, a percent sign is
  2794. printed in front of the number. If rounding
  2795. causes the number to exceed the field, a percent
  2796. sign will be printed in front of the rounded
  2797. number.
  2798. PRINT USING "##.##";111.22
  2799. %111.22
  2800. PRINT USING ".##";.999
  2801. %l.00
  2802. If the number of digits specified exceeds 24, an
  2803. "Illegal function call" error will result.
  2804. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-70
  2805. 2.51 PRINT# AND PRINT# USING
  2806. Format PRINT#<file number>,[USING <string exp>;]<list
  2807. of expressions>
  2808. Purpose To write data to a sequential disk file.
  2809. Remarks <file number> is the number used when the file
  2810. was OPENed for output. <string exp> consists of
  2811. formatting characters as described in Section
  2812. 2.50, "PRINT USING." The expressions in <list of
  2813. expressions> are the numeric and/or string
  2814. expressions that will be written to the file.
  2815. PRINT# does not compress data on the disk. An
  2816. image of the data is written to the disk, just
  2817. as it would be displayed on the terminal screen
  2818. with a PRINT statement. For this reason, care
  2819. should be taken to delimit the data on the disk,
  2820. so that it will be input correctly from the
  2821. disk.
  2822. In the list of expressions, numeric expressions
  2823. should be delimited by semicolons. For example:
  2824. PRINT#1,A;B;C;X;Y:Z
  2825. (If commas are used as delimiters, the extra
  2826. blanks that are inserted between print fields
  2827. will also be written to the disk.)
  2828. String expressions must be separated by
  2829. semicolons in the list. To format the string
  2830. expressions correctly on the disk, use explicit
  2831. delimiters in the list of expressions.
  2832. For example, let A$="CAMERA" and B$="93604-l".
  2833. The statement
  2834. PRINT#1,A$;13$
  2835. would write CAMERA93604-1 to the disk. Because
  2836. there are no delimiters, this could not be input
  2837. as two separate strings. To correct the
  2838. problem, insert explicit delimiters into the
  2839. PRINT# statement as follows:
  2840. PRINT#1,A$;",";BS
  2841. The image written to disk is
  2842. CAMERA,93604-1
  2843. which can be read back into two string
  2844. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-71
  2845. variables.
  2846. If the strings themselves contain commas,
  2847. semicolons, significant leading blanks, carriage
  2848. returns, or line feeds, write them to disk
  2849. surrounded by explicit quotation marks,
  2850. CHR$(34).
  2851. For example, let A$="CAMERA, AUTOMATIC" and
  2852. B$=" 93604-1". The statement
  2853. PRINT#1,A$;B$
  2854. would write the following image to disk:
  2855. CAMERA, AUTOMATIC 93604-1
  2856. And the statement
  2857. INPUT#1,A$,B$
  2858. would input "CAMERA" to A$ and
  2859. "AUTOMATIC 93604-1" to B$. To separate these
  2860. strings properly on the disk, write double
  2861. quotation marks to the disk image using
  2862. CHR$(34). The statement
  2863. PRINT#1,CHR$(34);A$;CHR$(34);CHR$(34);B$;CHR$(34)
  2864. writes the following image to disk:
  2865. "CAMERA, AUTOMATIC"" 93604-1"
  2866. And the statement
  2867. INPUT#1,A$,B$
  2868. would input "CAMERA, AUTOMATIC" to A$ and
  2869. " 93604-1" to B$.
  2870. The PRINT; statement may also be used with the
  2871. USING option to control the format of the disk
  2872. file. For example:
  2873. PRINT#1,USING"$$###.##,";J;K;L
  2874. For more examples using PRINT#, see "Microsoft
  2875. BASIC Disk I/O," in the Microsoft BASIC User's
  2876. Guide.
  2877. See also "WRITE#," Section 2.68.
  2878. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-72
  2879. 2.52 PUT
  2880. Format PUT [#]<file number>[,<record number>]
  2881. Purpose To write a record from a random buffer to a
  2882. random disk file.
  2883. Remarks <file number> is the number under which the file
  2884. was OPENed. If <record number> is omitted, the
  2885. record will assume the next available record
  2886. number (after the last PUT). The largest
  2887. possible record number is 32,767. The smallest
  2888. record number is 1.
  2889. Example See "Microsoft BASIC Disk I/0," in the Microsoft
  2890. BASIC User's Guide.
  2891. Note PRINT#, PRINT# USING, and WRITE# may be used to
  2892. put characters in the random file buffer before
  2893. executing a PUT statement.
  2894. In the case of WRITE#, Microsoft BASIC pads the
  2895. buffer with spaces up to the carriage return.
  2896. Any attempt to read or write past the end of the
  2897. buffer causes a "Field overflow" error.
  2898. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-73
  2899. 2.53 RANDOMIZE
  2900. Format RANDOMIZE [ <expression>]
  2901. Purpose To reseed the random number generator.
  2902. Remarks If <expression> is omitted, Microsoft BASIC
  2903. suspends program execution and asks for a value
  2904. by printing
  2905. Random Number Seed (-32768 to 32767)?
  2906. before executing RANDOMIZE.
  2907. If the random number generator is not reseeded,
  2908. the RND function returns the same sequence of
  2909. random numbers each time the program is RUN. To
  2910. change the sequence of random numbers every time
  2911. the program is RUN, place a RANDOMIZE statement
  2912. at the beginning of the program and change the
  2913. argument with each RUN.
  2914. Example 10 RANDOMIZE
  2915. 20 FOR I=1 TO 5
  2916. 30 PRINT RND;
  2917. 40 NEXT I
  2918. RUN
  2919. Random Number Seed (-32768 to 32767)? 3
  2920. (user types 3)
  2921. .88598 .484668 .586328 .119426 .709225
  2922. Ok
  2923. RUN
  2924. Random Number Seed (-32768 to 32767)? 4
  2925. (user types 4 for new sequence)
  2926. .803506 .162462 .929364 .292443 .322921
  2927. Ok
  2928. RUN
  2929. Random Number Seed (-32768 to 32767)? 3
  2930. (same sequence as first RUN)
  2931. .88598 .484668 .586328 .119426 .709225
  2932. Ok
  2933. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-74
  2934. 2.54 READ
  2935. Format READ <list of variables>
  2936. Purpose To read values from a DATA statement and assign
  2937. them to variables. (See "DATA," Section 2.10.)
  2938. Remarks A READ statement must always be used in
  2939. conjunction with a DATA statement. READ
  2940. statements assign variables to DATA statement
  2941. values on a one-to-one basis. READ statement
  2942. variables may be numeric or string, and the
  2943. values read must agree with the variable types
  2944. specified. If they do not agree, a "Syntax
  2945. error" will result.
  2946. A single READ statement may access one or more
  2947. DATA statements (they will be accessed in
  2948. order) , or several READ statements may access
  2949. the same DATA statement. If the number of
  2950. variables in <list of variables> exceeds the
  2951. number of elements in the DATA statement(s), an
  2952. "Out of data" error message is printed. If the
  2953. number of variables specified is fewer than the
  2954. number of elements in the DATA statement(s),
  2955. subsequent READ statements will begin reading
  2956. data at the first unread element. If there are
  2957. no subsequent READ statements, the extra data is
  2958. ignored.
  2959. To reread DATA statements from the start, use
  2960. the RESTORE statement (see "RESTORE," Section
  2961. 2.57)
  2962. Example 1
  2963. .
  2964. .
  2965. .
  2966. 80 FOR 1=1 TO 10
  2967. 90 READ A(I)
  2968. 100 NEXT
  2969. 110 DATA 3.08,5.19,3.12,3.98,4.24
  2970. 120 DATA 5.08,5.55,4.00,3.16,3.37
  2971. .
  2972. .
  2973. .
  2974. This program segment READs the values from the
  2975. DATA statements into the array A. After
  2976. execution, the value of A(1) will be 3.08, and
  2977. so on.
  2978. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-75
  2979. Example 2 LIST
  2980. 10 PRINT "CITY", "STATE", " ZIP"
  2981. 20 READ C$,S$,Z
  2982. 30 DATA "DENVER,", COLORADO, 80211
  2983. 40 PRINT C$,S$,Z
  2984. Ok
  2985. RUN
  2986. CITY STATE ZIP
  2987. DENVER, COLORADO 80211
  2988. Ok
  2989. This program READS string and numeric data from
  2990. the DATA statement in line 30.
  2991. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-76
  2992. 2.55 REM
  2993. Format REM <remark>
  2994. Purpose To allow explanatory remarks to be inserted in a
  2995. program.
  2996. Remarks REM statements are not executed but are output
  2997. exactly as entered when the program is listed.
  2998. REM statements may be branched into from a GOTO
  2999. or GOSUB statement. Execution will continue
  3000. with the first executable statement after the
  3001. REM statement.
  3002. Remarks may be added to the end of a line by
  3003. preceding the remark with a single quotation
  3004. mark instead of :REM.
  3005. ImportantDo not use this in a data statement, because it
  3006. would be considered legal data.
  3007. Example
  3008. .
  3009. .
  3010. .
  3011. 120 REM CALCULATE AVERAGE VELOCITY
  3012. 130 FOR 1=1 TO 20
  3013. 140 SUM=SUM + V(I)
  3014. .
  3015. .
  3016. .
  3017. or
  3018. .
  3019. .
  3020. .
  3021. 120 FOR I=1 TO 20 'CALCULATE AVERAGE VELOCITY
  3022. 130 SUM=SUM+V(I)
  3023. 140 NEXT I
  3024. .
  3025. .
  3026. .
  3027. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-77
  3028. 2.56 RENUM
  3029. Format RENUM [[<new number>][,[<old number>][,<increment>]]]
  3030. Purpose To renumber program lines.
  3031. Remarks <new number> is the first line number to be used
  3032. in the new sequence. The default is 10. <old
  3033. number> is the line in the current program where
  3034. renumbering is to begin. The default is the
  3035. first line of the program. <increment> is the
  3036. increment to be used in the new sequence. The
  3037. default is 10.
  3038. RENUM also changes all line number references
  3039. following GOTO, GOSUB, THEN, ON...GOTO,
  3040. ON...GOSUB, and ERL statements to reflect the
  3041. new line numbers. If a nonexistent line number
  3042. appears after one of these statements, the error
  3043. message "Undefined line number in xxxxx" is
  3044. printed. The incorrect line number reference is
  3045. not changed by RENUM, but line number yyyyy may
  3046. be changed.
  3047. No te RENUM cannot be used to change the order of
  3048. program lines (for example, RENUM 15,30 when the
  3049. program has three lines numbered 10, 20 and 30)
  3050. or to create line numbers greater than 65529.
  3051. An "Illegal function call" error will result.
  3052. Examples RENUM Renumbers the entire program.
  3053. The first new line number
  3054. will be 10. Lines will be
  3055. numbered in increments of 10.
  3056. RENUM 300,50 Renumbers the entire pro-
  3057. gram. The first new line
  3058. number will be 300. Lines
  3059. will be numbered in
  3060. increments of 50.
  3061. RENUM 1000,900,20 Renumbers the lines from
  3062. 900 up so they start with
  3063. line number 1000 and are
  3064. numbered in increments of 20.
  3065. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-78
  3066. 2.57 RESTORE
  3067. Format RESTORE [ <line number>]
  3068. Purpose To allow DATA statements to be reread from a
  3069. specified line.
  3070. Remarks After a RESTORE statement is executed, the next
  3071. READ statement accesses the first item in the
  3072. first DATA statement in the program. If <line
  3073. number> is specified, the next READ statement
  3074. accesses the first item in the specified DATA
  3075. statement.
  3076. Example 10 READ A,B,C
  3077. 20 RESTORE
  3078. 30 READ D,E,F
  3079. 40 DATA 57, 68, 79
  3080. .
  3081. .
  3082. .
  3083. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-79
  3084. 2.58 RESUME
  3085. Formats RESUME
  3086. RESUME 0
  3087. RESUME NEXT
  3088. RESUME <line number>
  3089. Purpose To continue program execution after an error
  3090. recovery procedure has been performed.
  3091. Remarks Any one of the four formats shown above may be
  3092. used, depending upon where execution is to
  3093. resume:
  3094. RESUME Execution resumes at the
  3095. or statement which caused the
  3096. RESUME 0 error.
  3097. RESUME NEXT Execution resumes at the
  3098. statement immediately fol-
  3099. lowing the one which
  3100. caused the error.
  3101. RESUME <line number> Execution resumes at
  3102. <line number>.
  3103. A RESUME statement that is not in an error
  3104. handling routine causes a "RESUME without error"
  3105. message to be printed.
  3106. Example 10 ON ERROR GOTO 900
  3107. .
  3108. .
  3109. .
  3110. 900 IF (ERR=230)AND(ERL=90) THEN PRINT "TRY
  3111. AGAIN" :RESUME 80
  3112. .
  3113. .
  3114. .
  3115. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-80
  3116. 2.59 RUN
  3117. Format 1 RUN [ <line number>]
  3118. Purpose To execute the program currently in memory.
  3119. Remarks If <line number> is specified, execution begins
  3120. on that line. Otherwise, execution begins at
  3121. the lowest line number. Microsoft BASIC always
  3122. returns to command level after a RUN is
  3123. executed.
  3124. Example RUN
  3125. Format 2 RUN <filename>[,R]
  3126. Purpose To load a file from disk into memory and run it.
  3127. Remarks <filename> is the name used when the file was
  3128. SAVEd. (Your operating system may append a
  3129. default filename extension if one was not
  3130. supplied in the SAVE command. Refer to
  3131. "Microsoft BASIC Disk I/0," in the Microsoft
  3132. BASIC User's Guide for information about
  3133. possible filename extensions under your
  3134. operating system.)
  3135. RUN closes all open files and deletes the
  3136. current contents of memory before loading the
  3137. designated program. However, with the "R"
  3138. option, all data files remain OPEN.
  3139. Example RUN "NEWFIL",R
  3140. See also "Microsoft BASIC Disk I/O," in the
  3141. Microsoft BASIC User's Guide.
  3142. Note Microsoft BASIC Compiler supports the RUN and
  3143. RUN <line number> forms of the RUN statement.
  3144. Microsoft BASIC Compiler does not support the
  3145. "R" option with RUN. If you want this feature,
  3146. the CHAIN statement should be used.
  3147. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-81
  3148. 2.60 SAVE
  3149. Format SAVE <filename>[{,A|,P}]
  3150. Purpose To save a program file on disk.
  3151. Remarks <filename> is a quoted string that conforms to
  3152. your operating system's requirements for
  3153. filenames. (Your operating system may append a
  3154. default filename extension if one was not
  3155. supplied in the SAVE command. Refer to
  3156. "Microsoft BASIC Disk I/O,' in the Microsoft
  3157. BASIC User's Guide for information about
  3158. possible filename extensions under your
  3159. operating system.) If <filename> already exists,
  3160. the file will be written over.
  3161. Use the A option to save the file in ASCII
  3162. format. Otherwise, Microsoft BASIC saves the
  3163. file in a comoressed binary format. ASCII
  3164. format takes more space on the disk, but some
  3165. disk access requires that files be in ASCII
  3166. format. For instance, the MERGE command
  3167. requires an ASCII format file, and some
  3168. operating system commands such as LIST may
  3169. require an ASCII format file.
  3170. Use the P option to protect the file by saving
  3171. it in an encoded binary format. When a
  3172. protected file is later RUN (or LOADed), any
  3173. attempt to list or edit it will fail.
  3174. Examples SAVE "COM2",A
  3175. SAVE "PROG",P
  3176. See also "Microsoft BASIC Disk I/O,"
  3177. in the Microsoft BASIC User's Guide.
  3178. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-82
  3179. 2.61 STOP
  3180. Format STOP
  3181. Purpose To terminate program execution and return to
  3182. command level.
  3183. Remarks STOP statements may be used anywhere in a
  3184. program to terminate execution. When a STOP is
  3185. encountered, the following message is printed:
  3186. Break in line nnnnn
  3187. Unlike the END statement, the STOP statement
  3188. does not close files.
  3189. Microsoft BASIC always returns to command level
  3190. after a STOP is executed. Execution is resumed
  3191. by issuing a CONT command (see Section 2.8).
  3192. Example 10 INPUT A,B,C
  3193. 20 K=A^2*5.3:L=B^3/.26
  3194. 30 STOP
  3195. 40 M=C*K+100:PRINT M
  3196. RUN
  3197. ? 1,2,3
  3198. BREAK IN 30
  3199. Ok
  3200. PRINT L
  3201. 30.7692
  3202. Ok
  3203. CONT
  3204. 115.9
  3205. Ok
  3206. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-83
  3207. 2.62 SWAP
  3208. Format SWAP <variable>,<variable>
  3209. Purpose To exchange the values of two variables.
  3210. Remarks Any type variable may be SWAPped (integer,
  3211. single precision, double precision, string) , but
  3212. the two variables must be of the same type or a
  3213. "Type mismatch" error results.
  3214. Example LIST
  3215. 10 A$=" ONE " : B$=" ALL " : C$1="FOR"
  3216. 20 PRINT A$ C$ B$
  3217. 30 SWAP A$, B$
  3218. 40 PRINT A$ C$ B$
  3219. RUN
  3220. Ok
  3221. ONE FOR ALL
  3222. ALL FOR ONE
  3223. Ok
  3224. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-84
  3225. 2.63 TRON/TROFF
  3226. Format TRON
  3227. TROFF
  3228. Purpose To trace the execution of program statements.
  3229. Remarks As an aid in debugging, the TRON statement
  3230. (executed in either direct or indirect mode)
  3231. enables a trace flag that prints each line
  3232. number of the orogram as it is executed. The
  3233. numbers appear enclosed in square brackets. The
  3234. trace flag is disabled with the TROFF statement
  3235. (or when a NEW command is executed).
  3236. Example TRON
  3237. Ok
  3238. LIST
  3239. 10 K=10
  3240. 20 FOR J=1 TO 2
  3241. 30 L=K + 10
  3242. 40 PRINT J;K;L
  3243. 50 K=K+10
  3244. 60 NEXT
  3245. 70 END
  3246. Ok
  3247. RUN
  3248. [10] [20] [30] [40] 1 10 20
  3249. [50] [60] [30] [40] 2 20 30
  3250. [50] [60] [70]
  3251. Ok
  3252. TROFF
  3253. Ok
  3254. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-85
  3255. 2.64 WAIT
  3256. Format WAIT <port number>,I[,J]
  3257. where I and J are integer expressions.
  3258. Purpose To suspend program execution while monitoring
  3259. the status of a machine input port.
  3260. Remarks The WAIT statement causes execution to be
  3261. suspended until a specified machine input port
  3262. develops a specified bit pattern. The data read
  3263. at the port is exclusive OR'ed with the integer
  3264. expression J, and then AND'ed with I. If the
  3265. result is zero, Microsoft BASIC l000s back and
  3266. reads the data at the port again. If the result
  3267. is nonzero, execution continues with the next
  3268. statement. If J is omitted, it is assumed to be
  3269. zero
  3270. Important It is possible to enter an infinite loop with
  3271. the WAIT statement, in which case it will be
  3272. necessary to manually restart the machine. To
  3273. avoid this, WAIT must have the specified value
  3274. at <port number> during some paint in the
  3275. program execution.
  3276. Example 100 WAIT 32,2
  3277. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-86
  3278. 2.65 WHILE...WEND
  3279. Format WHILE <expression>
  3280. [<loop statements>]
  3281. WEND
  3282. Purpose To execute a series of statements in a loop as
  3283. long as a given condition is true.
  3284. Remarks If <expression> is not zero (i.e., true), <loop
  3285. statements> are executed until the WEND
  3286. statement is encountered. Microsoft BASIC then
  3287. returns to the WHILE statement and checks
  3288. <expression>. If it is still true, the process
  3289. is repeated. If it is not true, execution
  3290. resumes with the statement following the WEND
  3291. statement.
  3292. WHILE/WEND loops may be nested to any level.
  3293. Each WEND will match the most recent WHILE. An
  3294. unmatched WHILE statement causes a "WHILE
  3295. without WEND" error, and an unmatched WEND
  3296. statement causes a "WEND without WHILE" error.
  3297. Example 90 'BUBBLE SORT ARRAY A$
  3298. 100 FLIPS=1 'FORCE ONE PASS THRU LOOP
  3299. 110 WHILE FLIPS
  3300. 115 FLIPS=0
  3301. 120 FOR I=1 TO J-1
  3302. 130 IF A$(I)>A$(I+1.1) THEN
  3303. SWAP A$(I),A$(I+1):FLIPS=1
  3304. 140 NEXT I
  3305. 150 WEND
  3306. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-87
  3307. 2.66 WIDTH
  3308. Format WIDTH [LPRINT ]<integer expression>
  3309. Purpose To set the printed line width in number of
  3310. characters for the terminal or line printer.
  3311. Remarks If the LPRINT option is omitted, the line width
  3312. is set at the terminal. If LPRINT is included,
  3313. the line width is set at the line printer.
  3314. <integer expression> must have a value in the
  3315. range 15 to 255. The default width is 72
  3316. characters.
  3317. If <integer expression> is 255, the line width
  3318. is "infinite"; that is, Microsoft BASIC never
  3319. inserts a carriage return. However, the
  3320. position of the cursor or the print head, as
  3321. given by the POS or LPOS function, returns to
  3322. zero after position 255.
  3323. Example 10 PRINT "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  3324. RUN
  3325. ABCDEFGHIJKLMNOPQRSTUVWXYZ
  3326. Ok
  3327. WIDTH 18
  3328. Ok
  3329. RUN
  3330. ABCDEFGHIJKLMNOPQR
  3331. STUVWXYZ
  3332. Ok
  3333. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-88
  3334. 2.67 WRITE
  3335. Format WRITE [<list of expressions>]
  3336. Purpose To output data at the terminal.
  3337. Remarks If <list of exressions> is omitted, a blank
  3338. line is output. If <list of expressions> is
  3339. included, the values of the expressions are
  3340. output at the terminal. The expressions in the
  3341. list may be numeric and/or string expressions.
  3342. They must be separated by commas.
  3343. When the printed items are output, each item is
  3344. separated frua the last by a comma. Printed
  3345. strings are delimited by auotation marks. After
  3346. the last item in the list is printed, Microsoft
  3347. BASIC inserts a carriage return/line feed.
  3348. WRITE outputs numeric values using the same
  3349. format as the PRINT statement. (See Section
  3350. 2.49.)
  3351. Example 10 A=80:B=90:C$="THAT'S ALL"
  3352. 20 WRITE A,B,C$
  3353. RUN
  3354. 80, 90,"THAT'S ALL"
  3355. Ok
  3356. MICROSOFT BASIC COMMANDS AND STATEMENTS Page 2-89
  3357. 2.68 WRITE#
  3358. Format WRITE#<file number>,<list of expressions>
  3359. Purpose To write data to a sequential file.
  3360. Remarks <file number> is the number under which the file
  3361. was OPENed in "0" mode (see "OPEN," Section
  3362. 2.45). The expressions in the list are string
  3363. or numeric expressions. They must be separated
  3364. by commas.
  3365. The difference between WRITE# and PRINT# is that
  3366. wRITE# inserts commas between the items as they
  3367. are written to disk and delimits strings with
  3368. quotation marks. Therefore, it is not necessary
  3369. for the user to put explicit delimiters in the
  3370. list. A carriage return/line feed sequence is
  3371. inserted after the last item in the list is
  3372. written to disk.
  3373. Example Let A$="CAMERA" and B$="93604-1"
  3374. The statement:
  3375. WRITE#1,A$,B$
  3376. writes the following image to disk:
  3377. "CAMERA","93604-1"
  3378. A subsequent INPUT# statement, such as
  3379. INPUT#1,A$,B$
  3380. would input "CAMERA" to A$ and "93604-1" to B$.
  3381. <blank page>
  3382. Chapter 3 Microsoft BASIC Functions
  3383. Introduction
  3384. 3.1 ABS
  3385. 3.2 ASC
  3386. 3.3 ATN
  3387. 3.4 CDBL
  3388. 3.5 CHR$
  3389. 3.6 CINT
  3390. 3.7 COS
  3391. 3.8 CSNG
  3392. 3.9 CVI, CVS, CVD
  3393. 3.10 EOF
  3394. 3.11 EXP
  3395. 3.12 FIX
  3396. 3.13 FRE
  3397. 3.14 HEX$
  3398. 3.15 INKEY$
  3399. 3.16 INP
  3400. 3.17 INPUT$
  3401. 3.18 INSTR
  3402. 3.19 INT
  3403. 3.20 LEFT$
  3404. 3.21 LEN
  3405. 3.22 LOC
  3406. 3.23 LOG
  3407. 3.24 LPOS
  3408. 3.25 MIDS
  3409. 3.26 MIK$, MKS$, MIMS
  3410. 3.27 OCT$
  3411. 3.28 PEEK
  3412. 3.29 POS
  3413. 3.30 RIGHT$
  3414. 3.31 RND
  3415. 3.32 SGN
  3416. 3.33 SIN
  3417. 3.34 SPACE$
  3418. 3.35 SPC
  3419. 3.36 SQR
  3420. 3.37 STR$
  3421. 3.38 STRING$
  3422. 3.39 TAB
  3423. 3.40 TAN
  3424. 3.41 USR
  3425. 3.42 VAL
  3426. 3.43 VARPTR
  3427. <blank page>
  3428. CHAPTER 3
  3429. MICROSOFT BASIC FUNCTIONS
  3430. Microsoft BASIC intrinsic functions are described in this
  3431. chapter. The functions may be called from any program
  3432. without further definition.
  3433. Arguments to functions are always enclosed in parentheses.
  3434. In the formats given for the functions in this chapter, the
  3435. arguments have been abbreviated as follows:
  3436. X and Y Represent any numeric expressions.
  3437. I and J Represent integer expressions.
  3438. X$ and Y$ Represent strina expressions.
  3439. If a floating-point value is supplied where an integer is
  3440. required, Microsoft BASIC will round the fractional portion
  3441. and use the resulting integer.
  3442. Note With Microsoft BASIC Interpreter, only integer and
  3443. single precision results are returned by functions. Double
  3444. precision functions are supported only by the Microsoft
  3445. BASIC Compiler.
  3446. MICROSOFT BASIC FUNCTIONS Page 3-2
  3447. 3.1 ABS
  3448. Format ABS(X)
  3449. Action Returns the -absolute value of the expression X.
  3450. Example PRINT ABS(7*(-5))
  3451. 35
  3452. Ok
  3453. 3.2 ASC
  3454. Format ASC (X$)
  3455. Action Returns a numerical value that is the ASCII code
  3456. for the first character of the string X$. (See
  3457. Appendix C for ASCII codes.) If X$ is null, an
  3458. "Illegal function call" error is returned.
  3459. Example 10 X$="TEST"
  3460. 20 PRINT ASC(X$)
  3461. RUN
  3462. 84
  3463. Ok
  3464. See the CHR$ function, Section 3.5, for details
  3465. on ASCII-to--string conversion.
  3466. MICROSOFT BASIC FUNCTIONS Page 3-3
  3467. 3.3 ATN
  3468. Format ATN(X)
  3469. Action Returns the arctangent of X in radians. Result
  3470. is in the range -pi/2 to pi/2. The express ion X
  3471. may be any numeric type, but the evaluation of
  3472. ATN is always performed in single precision.
  3473. Example 10 INPUT X
  3474. 20 PRINT ATN(X)
  3475. RUN
  3476. ? 3
  3477. 1.24905
  3478. Ok
  3479. 3.4 CDBL
  3480. Format CDBL(X)
  3481. Action Converts X to a double precision number.
  3482. Example 10 A=454.67
  3483. 20 PRINT A;CDBL(A)
  3484. RUN
  3485. 454.67 454.6700134277344
  3486. Ok
  3487. MICROSOFT BASIC FUNCTIONS Page 3-4
  3488. 3.5 CHRS
  3489. Format CHRS(I)
  3490. Action Returns a string whose one character is ASCII
  3491. character I. (ASCII codes are listed in
  3492. Appendix C.) CHR$ is commonly used to send a
  3493. special character to the terminal. For
  3494. instance, the BET character (CHR$(7)) could be
  3495. sent as a preface to an error message, or a form
  3496. feed (CHR$(12)) could be sent to clear a
  3497. terminal screen and return the cursor to the
  3498. home position.
  3499. Example PRINT CHR$(66)
  3500. B
  3501. Ok
  3502. See the ASC function, Section 3.2, for details
  3503. on ASCII-to-numeric conversion.
  3504. 3.6 CINT
  3505. Format CINT(X)
  3506. Action Converts X to an integer by rounding the
  3507. fractional portion. If X is not in the range
  3508. -32768 to 32767, an "Overflow" error occurs.
  3509. Example PRINT CINT(45.67)
  3510. 46
  3511. Ok
  3512. See the CDBL and CSNG functions for details on
  3513. converting numbers to the double precision and
  3514. single precision data type, respectively. See
  3515. also the FIX and INT functions, both of which
  3516. return integers.
  3517. MICROSOFT BASIC FUNCTIONS Page 3-5
  3518. 3.7 COS
  3519. Format COS(X)
  3520. Action Returns the cosine of X in radians. The
  3521. calculation of COS(X) is performed in single
  3522. precision.
  3523. Example 10 X2*COS(.4)
  3524. 20 PRINT X
  3525. RUN
  3526. 1.84212
  3527. Ok
  3528. 3.8 CSNG
  3529. Format CSNG(X)
  3530. Action Converts X to a single precision number.
  3531. Example 10 A4 = 975.34214
  3532. 20 PRINT /4; CSNG(A#)
  3533. RUN
  3534. 975.3421 975.342
  3535. Ok
  3536. See the CINT and CDBIJ functions for converting
  3537. numbers to the integer and double precision data
  3538. types, respectively.
  3539. MICROSOFT BASIC FUNCTIONS Page 3-6
  3540. 3.9 CVI, CVS, CVD
  3541. Format CVI (<2-byte string>)
  3542. CVS(<4-byte string>)
  3543. CVD(<8-byte string>)
  3544. Action Convert string values to numeric values.
  3545. Numeric values that are read in from a random
  3546. disk file must be converted frcm strings back
  3547. into numbers. CVI converts a 2-byte string to
  3548. an integer. CVS converts a 4-byte string to a
  3549. single precision number. CVD converts an 8-byte
  3550. string to a double precision number.
  3551. Example
  3552. 70 FIELD #1,4 AS N$, 12 AS B$,
  3553. 80 GET #1
  3554. 90 Y=CVS(N$)
  3555. See also "MKI$, MKSS, MKD$," Section 3.26 and
  3556. "Microsoft BASIC Disk I/O," in the Microsoft
  3557. BASIC User's Guide.
  3558. 3.10 EOF
  3559. Format EOF(<file number>)
  3560. Action Returns -1 (true) if the end of a sequential
  3561. file has been reached. Use EOF to test for
  3562. end-of-file while INPUTting, to avoid "Input
  3563. past end" errors.
  3564. Example 10 OPEN "I",1,"DATA"
  3565. 20 C=0
  3566. 30 IF EOF(1) THEN 100
  3567. 40 INPUT 41,M(C)
  3568. 50 C=C+1:GOTO 30
  3569. MICROSOFT BASIC FUNCTIONS Page 3-7
  3570. 3.11 EXP
  3571. Format EXP(X)
  3572. Action Returns e (base of natural logarithms) to the
  3573. power of X. X must be <=87.3365. If EXP
  3574. overflows, the "Overflow" error message is
  3575. displayed, machine infinity with the appropriate
  3576. sign is supplied as the result, and execution
  3577. continues.
  3578. Example 10 X=5
  3579. 20 PRINT EXP(X-1)
  3580. RUN
  3581. 54.5982
  3582. Ok
  3583. 3.12 FIX
  3584. Format FIX(X)
  3585. Action Returns the truncated integer part of X. FIX(X)
  3586. is equivalent to SGN(X)*INT(ABS(X)). The major
  3587. difference between FIX and INT is that FIX does
  3588. not return the next lower number for negative X.
  3589. Examples PRINT FIX(58.75)
  3590. 58
  3591. Ok
  3592. PRINT FIX(-58.75)
  3593. -58
  3594. Ok
  3595. MICROSOFT BASIC FUNCTIONS Page 3-8
  3596. 3.13 FRE
  3597. Format FRE(0)
  3598. FRE("")
  3599. Action Arguments to FRE are dummy arguments. FRE
  3600. returns the number of bytes in memory not being
  3601. used by Microsoft BASIC.
  3602. FRE("") forces a garbage collection before
  3603. returning the number of free bytes. Be
  3604. patient: garbage collection may take 1 to 1-1/2
  3605. minutes.
  3606. Microsoft BASIC will not initiate garbage
  3607. collection until all free memory has been used
  3608. up. Therefore, using FRE("") periodically will
  3609. result in shorter delays for each garbage
  3610. collection.
  3611. Example PRINT FRE(0)
  3612. 14542
  3613. Ok
  3614. 3.14 HEX$
  3615. Format HEX$(X)
  3616. Action Returns a string which represents the
  3617. hexadecimal value of the decimal argument. X is
  3618. rounded to an integer before HEX$ (X) is
  3619. evaluated.
  3620. Example 10 INPUT X
  3621. 20 A$=HEX$(X)
  3622. 30 PRINT X "DECIMAL IS " A$ " HEXADECIMAL"
  3623. RUN
  3624. ? 32
  3625. 32 DECIMAL IS 20 HEXADECIMAL
  3626. Ok
  3627. See the OCT$ function, Section 3.27, for details
  3628. on octal conversion.
  3629. MICROSOFT BASIC FUNCTIONS Page 3-9
  3630. 3.15 INKEY$
  3631. Format INKEY$
  3632. Action Returns either a one-character string containing
  3633. a character read from the terminal or a null
  3634. string if no character is pending at the
  3635. terminal. No characters will be echoed. All
  3636. characters are passed through to the program
  3637. except for Control-C, which terminates the
  3638. program. (With Microsoft BASIC Compiler,
  3639. Control-C is also passed through to the
  3640. program.)
  3641. Example 1000 'TIMED INPUT SUBROUTINE
  3642. 1010 RESPONSE$=""
  3643. 1020 FOR I%=1 TO TIMELIMIT%
  3644. 1030 A$=INKEY$ : IF LEN(AS)=0 THEN 1060
  3645. 1040 IF ASC(A$)=13 THEN TIMEOUT%=0 : RETURN
  3646. 1050 RESPONSE$=RESPONSE$+A$
  3647. 1060 NEXT I%
  3648. 1070 TIMEOUT%=1 : RETURN
  3649. 3.16 INP
  3650. Format INP(I)
  3651. Action Returns the byte read from port I. I must be in
  3652. the range 0 to 255. INP is the complementary
  3653. function to the OUT statement, Section 2.47.
  3654. Example 100 A=INP(255)
  3655. MICROSOFT BASIC FUNCTIONS Page 3-10
  3656. 3.17 INPUT$
  3657. Format INPUT$(X[,[#]Y])
  3658. Action Returns a string of X characters, read from the
  3659. terminal or from file number Y. If the terminal
  3660. is used for input, no characters will be echoed.
  3661. All control characters are passed through except
  3662. Control-C, which is used to interrupt the
  3663. execution of the INPUT$ function.
  3664. Example 1 5 'LIST THE CONTENTS OF A SEQUENTIAL FILE IN
  3665. HEXADECIMAL
  3666. 10 OPEN"I",1,"DATA"
  3667. 20 IF EOF(1) THEN 50
  3668. 30 PRINT HEX$(ASC(INPUT$(1,#1)));
  3669. 40 GOTO 20
  3670. 50 PRINT
  3671. 60 END
  3672. Example 2
  3673. 100 PRINT "TYPE P TO PROCEED OR S TO STOP"
  3674. 110 X$=INPUT$(1)
  3675. 120 IF X$="P" THEN 500
  3676. 130 IF X$="S" THEN 700 ELSE 100
  3677. MICROSOFT BASIC FUNCTIONS Page 3-11
  3678. 3.18 INSTR
  3679. Format TNSTR([I,]X$,Y$)
  3680. Action Searches for the first occurrence of string Y$
  3681. in X$, and returns the position at which the
  3682. match is found. Optional offset I sets the
  3683. position for starting the search. I must be in
  3684. the range 1 to 255. If I is greater than the
  3685. number of characters in X$ (LEN(X$)), or if X$
  3686. is null or Y$ cannot be found, INSTR returns 0.
  3687. If Y$ is null, INSTR returns I or 1. X$ and Y$
  3688. may be string variables, string expressions, or
  3689. string literals.
  3690. Example 10 X$="ABCDEB"
  3691. 20 Y$="B"
  3692. 30 PRINT INSTR(X$,Y$);INSTR(4,X$,Y$)
  3693. RUN
  3694. 2 6
  3695. Ok
  3696. Note If I=0 is specified, the "Illegal function call"
  3697. error message will be returned.
  3698. MICROSOFT BASIC FUNCTIONS Page 3-12
  3699. 3.19 INT
  3700. Format INT(x)
  3701. Action Returns the largest integer <=X.
  3702. Examples PRINT INT(99.89)
  3703. 99
  3704. Ok
  3705. PRINT INT{-12.11)
  3706. -13
  3707. Ok
  3708. See the CINT and FIX functions, Sections 3.6 and
  3709. 3.12, respectively, which also return integer
  3710. values.
  3711. 3.20 LEFT$
  3712. Format LEFT$(X$,I)
  3713. Action Returns a string comprising the leftmost I
  3714. characters of X$. I must be in the range 0 to
  3715. 255. If I is greater than the number of
  3716. characters in X$ (LEN(X$)), the entire string
  3717. (X$) will be returned. If I=0, the null string
  3718. (length zero) is returned.
  3719. Example 10 A$="BASIC"
  3720. 20 B$=LEFT$(A$,5)
  3721. 30 PRINT B$
  3722. BASIC
  3723. Ok
  3724. Also see the MID$ and RIGHT$ functions, Sections
  3725. 3.25 and 3.30, respectively.
  3726. MICROSOFT BASIC FUNCTIONS Page 3-13
  3727. 3.21 LEN
  3728. Format LEN(X$)
  3729. Action Returns the number of characters in X.
  3730. Nonprinting characters and blanks are counted.
  3731. Example 10 X$="PORTLAND, OREGON"
  3732. 20 PRINT LEN (X$)
  3733. 16
  3734. Ok
  3735. 3.22 LOC
  3736. Format LOC(<file number>)
  3737. where <file number> is the number under which
  3738. the file was OPENed.
  3739. Action With random disk files, LOC returns the record
  3740. number just read or written from a GET or PUT
  3741. statement. If the file was opened but no disk
  3742. I/O has been performed yet, LOC returns a 0.
  3743. With sequential files, LOC returns the number of
  3744. sectors (128-byte blocks) read from or written
  3745. to the file since it was OPENed.
  3746. Example 200 IF LOC(1)>50 THEN STOP
  3747. MICROSOFT BASIC FUNCTIONS Page 3-14
  3748. 3.23 LOG
  3749. Format LOG(X)
  3750. Action Returns the natural logarithm of X. X must be
  3751. greater than zero.
  3752. Example PRINT LOG(45/7)
  3753. 1.86075
  3754. Ok
  3755. 3.24 LPOS
  3756. Format LPOS(X)
  3757. Action Returns the current position of the line printer
  3758. print head within the line printer's buffer.
  3759. Does not necessarily give the physical position
  3760. of the print head. X is a dummy argument.
  3761. Example 100 IF LPOS(X)>60 THEN LPRINT CHR$(13)
  3762. MICROSOFT BASIC FUNCTIONS Page 3-15
  3763. 3.25 MID$
  3764. Format MID$(XS,I[,J])
  3765. Action Returns a string of length J characters from X$,
  3766. beginning with the Ith character. I and J must
  3767. be in the range 1 to 255. If J is omitted or if
  3768. there are fewer than J characters to the right
  3769. of the Ith character, all rightmost characters
  3770. beginning with the Ith character are returned.
  3771. If I is greater than the number of characters in
  3772. X$ (LEN(X$)), MID$ returns a null string.
  3773. Example LIST
  3774. 10 AS="GOOD "
  3775. 20 B$="MORNING EVENING AFTERNOON"
  3776. 30 PRINT AS;MID$(B$,9,7)
  3777. Ok
  3778. RUN
  3779. GOOD EVENING
  3780. Ok
  3781. Also see the LEFT$ and RIGHT$ functions,
  3782. Sections 3.20 and 3.30, respectively.
  3783. If 1=0 is specified, the "Illegal function call"
  3784. error message will be returned.
  3785. MICROSOFT BASIC FUNCTIONS Page 3-16
  3786. 3.26 MKI$, MKS$, MKD$
  3787. Format MKI$(<integer expression>)
  3788. MKS$(<single precision expression>)
  3789. MKD$(<double precision expression>)
  3790. Action Convert numeric values to string values. Any
  3791. numeric value that is placed in a randcm file
  3792. buffer with an LSET or RSET statement must be
  3793. converted to a string. MKI$ converts an integer
  3794. to a 2-byte string. MKS$ converts a single
  3795. precision number to a 4-byte string. MKD$
  3796. converts a double precision number to an 8-byte
  3797. string.
  3798. Example 90 AMT=(K+T)
  3799. 100 FIELD #1,8 AS D$,20 AS N$
  3800. 110 LSET D$=MKS$(AMT)
  3801. 120 LSET N$=A$
  3802. 130 PUT #1
  3803. See also "CVI, CVS, CVD," Section 3.9 and
  3804. "Microsoft BASIC Disk I/O," in the Microsoft
  3805. BASIC User's Guide.
  3806. MICROSOFT BASIC FUNCTIONS Page 3-17
  3807. 3.27 OCT$
  3808. Format OCT$(X)
  3809. Action Returns a string which represents the octal
  3810. value of the decimal argument. X is rounded to
  3811. an integer before OCT$(X) is evaluated.
  3812. Example PRINT OCT$(24)
  3813. 30
  3814. Ok
  3815. See the HEX$ function, Section 3.14, for details
  3816. on hexadecimal conversion.
  3817. 3.28 PEEK
  3818. Format PEEK(I)
  3819. Action Returns the byte read from the indicated memory
  3820. location (I).
  3821. Remarks The returned value is an integer in the range 0
  3822. to 255. I must be in the range -32768 to 65535.
  3823. (For the interpretation of a negative value of
  3824. I, see "VARPTR," Section 3.43.)
  3825. PEEK is the complementary function of the POKE
  3826. statement.
  3827. Example A=PEEK(&H5A00)
  3828. MICROSOFT BASIC FUNCTIONS Page 3-18
  3829. 3.29 POS
  3830. Format POS(I)
  3831. Action Returns the current cursor position. The
  3832. leftmost position is 1. X is a dummy argument.
  3833. Example IF P0S(X)>60 THEN PRINT CHR$(13)
  3834. Also see the LPOS function, Section 3.24.
  3835. 3.30 RIGHT$
  3836. Format RIGHT$(X$,I)
  3837. Action Returns the rightmost I characters of string X$.
  3838. If I is equal to the number of characters in X$
  3839. (LEN(X$)), returns X$. If I=0, the null string
  3840. (length zero) is returned.
  3841. Example 10 A$="DISK BASIC"
  3842. 20 PRINT RIGHT$(A$,5)
  3843. RUN
  3844. BASIC
  3845. Ok
  3846. Also see the LEFT$ and MID$ functions, Sections
  3847. 3.20 and 3.23, respectively.
  3848. MICROSOFT BASIC FUNCTIONS Page 3-19
  3849. 3.31 RND
  3850. Format RND[(X)]
  3851. Action Returns a random number between 0 and 1. The
  3852. same sequence of random numbers is generated
  3853. each time the program is RUN unless the random
  3854. number generator is reseeded (see "RANDOMIZE,"
  3855. Section 2.53). However, X<0 always restarts the
  3856. same sequence for any given X.
  3857. X>0 or X omitted generates the next random
  3858. number in the sequence. X=0 repeats the last
  3859. number generated.
  3860. Example 10 FOR 1=1 TO 5
  3861. 20 PRINT INT(RND*100);
  3862. 30 NEXT
  3863. RUN
  3864. 24 30 31 51 5
  3865. Ok
  3866. Note The values produced by the RND function
  3867. may vary with different implementations of
  3868. Microsoft BASIC.
  3869. 3.32 SGN
  3870. Format SGN(X)
  3871. Action If X>0, SGN(X) returns 1.
  3872. If X=0, SGN(X) returns 0.
  3873. If X<0, SGN(X) returns -1.
  3874. Example ON SGN(X)+2 GOTO 100,200,300
  3875. branches to 100 if X is negative, 200 if X is 0,
  3876. and 300 if X is positive.
  3877. MICROSOFT BASIC FUNCTIONS Page 3-20
  3878. 3.33 SIN
  3879. Format SIN(X)
  3880. Action Returns the sine of X in radians. SIN(X) is
  3881. calculated in single precision.
  3882. COS(X)=SIN(X+3.14159/2).
  3883. Example PRINT SIN(1.5)
  3884. .997495
  3885. Ok
  3886. See also the COS(X) function, Section 3.7.
  3887. 3.34 SPACE$
  3888. Format SPACE$(X)
  3889. Action Returns a string of spaces of length X. The
  3890. expression X is rounded to an integer and must
  3891. be in the range 0 to 255.
  3892. Example 10 FOR 1=1 TO 5
  3893. 20 X$=SPACE$(1)
  3894. 30 PRINT XS;I
  3895. 40 NEXT I
  3896. RUN
  3897. 1
  3898. 2
  3899. 3
  3900. 4
  3901. 5
  3902. Ok
  3903. Also see the SPC function, Section 3.35.
  3904. MICROSOFT BASIC FUNCTIONS Page 3-21
  3905. 3.35 SPC
  3906. Format SPC(I)
  3907. Action Prints I blanks on the terminal. SPC may only
  3908. be used with PRINT and LPRINT statements. I
  3909. must be in the range 0 to 255. A';' is assumed
  3910. to follow the SPC (I) command.
  3911. Example PRINT "OVER" SPC(15) "THERE"
  3912. OVER THERE
  3913. Ok
  3914. Also see the SPACE$ function, Section 3.34.
  3915. 3.36 SQR
  3916. Format SQR(X)
  3917. Action Returns the square root of X. X must be >=0.
  3918. Example 10 FOR X=10 TO 25 STEP 5
  3919. 20 PRINT X, SQR(X)
  3920. 30 NEXT
  3921. RUN
  3922. 10 3.16228
  3923. 15 3.87298
  3924. 20 4.47214
  3925. 25 5
  3926. Ok
  3927. MICROSOFT BASIC FUNCTIONS Page 3-22
  3928. 3.37 STR$
  3929. Format STR$(X)
  3930. Action Returns a string representation of the value of
  3931. X.
  3932. Example 5 REM ARITHMETIC FOR KIDS
  3933. 10 INPUT "TYPE A NUMBER";N
  3934. 20 ON LEN(STR$(N)) GOSUB 30,100,200,300,400,500
  3935. Also see the VAL function, Section 3.42.
  3936. 3.38 STRING$
  3937. Formats STRING$(I,J)
  3938. STRING$(I,X$)
  3939. Action Returns a string of length I whose characters
  3940. all have ASCII code J or the first character of
  3941. X$.
  3942. Example 10 X$=STRING$(10,45)
  3943. 20 PRINT XS "MONTHLY REPORT" X$
  3944. RUN MONTHLY REPORT
  3945. Ok
  3946. MICROSOFT BASIC FUNCTIONS Page 3-23
  3947. 3.39 TAB
  3948. Format TAB(I)
  3949. Action Spaces to position I on the terminal. If the
  3950. current print position is already beyond space
  3951. I, TAB goes to that position on the next line.
  3952. Space 1 is the leftmost position, and the
  3953. rightmost position is the width minus one.
  3954. must he in the range 1 to 255. TAB may only be
  3955. used in PRINT and LPRINT statements.
  3956. Example 10 PRINT "NAME" TAB (25) "AMOUNT" ; PRINT
  3957. 20 READ A$ ,Bu
  3958. 30 PRINT A TAB(25) BS
  3959. 40 DATA "G. T. JONES", "$25.00"
  3960. RUN
  3961. NAME AMOUNT
  3962. G. T. JONES $25.00
  3963. Ok
  3964. 3.40 TAN
  3965. Format TAN(X)
  3966. Action Returns the tangent of X in radians. TAIL (X! is
  3967. calculated in single precision. If TAN
  3968. overflows, the "Overflow" error message is
  3969. displayed, machine infinity with the appropriate
  3970. sign is supplied as the result, and execution
  3971. continues.
  3972. Example 10 Y=Q*TAN(X)/2
  3973. MICROSOFT BASIC FUNCTIONS Page 3-24
  3974. 3,41 USR
  3975. Format USR[<digit>](X)
  3976. Action Calls the user's assembly language subroutine
  3977. with the argument X. <digit> is in the range 0
  3978. to 9 and corresponds to the digit supplied with
  3979. the DEF USR statement for that routine. If
  3980. <digit> is omitted, USRO is assumed. See
  3981. "Assembly Language Subroutines," in the
  3982. Microsoft BASIC User's Guide.
  3983. Example 40 B=T*SIN(Y)
  3984. 50 C=USR(B/2)
  3985. 60 D=USR(B/3)
  3986. 3.42 VAL
  3987. Format VAL(X$)
  3988. Action Returns the numerical value of string X$. The
  3989. VAL function also strips leading blanks, tabs,
  3990. and linefeeds from the argument string. For
  3991. example,
  3992. VAL(" -3")
  3993. returns -3.
  3994. Example 10 READ NAME$,CITY$,STATE$,ZIP$
  3995. 20 IF VAL(ZIP$)<90000 OR VAL(Z1P$)>96699
  3996. TEEN PRINT NAME$ TAB(25) "CUT OF STATE"
  3997. 30 IF VAL(ZIP$)>=90601 AND VAL(ZIP$)<=90815
  3998. THEN PRINT NAMES TAB(25) "LONG BEACH"
  3999. See the STR$ function, Section 3.37, for details
  4000. on numeric-to-string conversion.
  4001. MICROSOFT BASIC FUNCTIONS Page 3-25
  4002. 3.43 VARPTR
  4003. Format 1 VARPTR(<variable name>)
  4004. Format 2 VARPTR(#<file number>)
  4005. Action Format 1
  4006. Returns the address of the first byte of data
  4007. identified with <variable name>. A value must
  4008. be assigned to <variable name' prior to
  4009. execution of VARPTR. Otherwise an "Illegal
  4010. function call" error results. Any type variable
  4011. name may be used (numeric, string, array). For
  4012. string variables, the address of the first byte
  4013. of the string descriptor is returned (see "BASIC
  4014. Assembly Language Subroutines," in the Microsoft
  4015. BASIC User's Guide for discussion of
  4016. descriptor). The address returned will be an
  4017. integer in the range 32767 to -32768. If a
  4018. negative address is returned, add it to 65536 to
  4019. obtain the actual address.
  4020. VARPTR is usually used to obtain the address of
  4021. a variable or array so it may be passed to an
  4022. assembly language subroutine. A function call
  4023. of the form VARPTR(A(0)) is usually specified
  4024. when passing an array, so that the
  4025. lowest-addressed element of the array is
  4026. returned.
  4027. Note All simple variables should be assigned before
  4028. calling VARPTR for an array, because the
  4029. addresses of the arrays change whenever a new
  4030. simple variable is assigned.
  4031. Format 2
  4032. For seauential files, returns the starting
  4033. address of the disk I/O buffer assigned to <file
  4034. number>. For random files, returns the address
  4035. of the FIELD buffer assigned to <file number>.
  4036. Example 100 X=USR(VARPTR(Y))
  4037. <blank page>
  4038. MICROSOFT BASIC FUNCTIONS
  4039. Appendices
  4040. A Error Codes and Error Messages
  4041. B Mathematical Functions
  4042. C ASCII Character Codes
  4043. D Microsoft BASIC Reserved Words
  4044. <blank page>
  4045. APPENDIX A
  4046. Error Codes and Error Messages
  4047. Code Number Message
  4048. NF 1 NEXT without FOR
  4049. A variable in a NEXT statement does not
  4050. correspond to any previously executed,
  4051. unmatched FOR statement variable.
  4052. SN 2 Syntax error
  4053. A line is encountered that contains some
  4054. incorrect sequence of characters (such as
  4055. unmatched parenthesis, misspelled command or
  4056. statement, incorrect punctuation, etc.).
  4057. Microsoft BASIC automatically enters edit
  4058. mode at the line that caused the error.
  4059. RG 3 Return without GOSUB
  4060. A RETURN statement is encountered for which
  4061. there is no previous, unmatched GOSUB
  4062. statement.
  4063. OD 4 Out of data
  4064. A READ statement is executed when there are
  4065. no DATA statements with unread data remaining
  4066. in the program.
  4067. FC 5 Illege function call
  4068. A parameter that is out of range is passed to
  4069. a math or string function. An FC error may
  4070. also occur as the result of:
  4071. 1. A negative or unreasonably large
  4072. subscript.
  4073. Page A-2
  4074. 2. A negative or zero argument with LOG,
  4075. 3. A negative argument to SQR,
  4076. 4. A negative mantissa with a noninteger
  4077. exponent.
  4078. 5. A call to a USR function for which the
  4079. starting address has not yet been given.
  4080. 6. An improper argument to MID$, LEFT$,
  4081. RIGHT$, INP, OUT, WAIT, PEEK, POKE, TAB,
  4082. SPC, STRING$, SPACES, INSTR, or
  4083. ON...COTO.
  4084. OV 6 Overflow
  4085. The result of a calculation is too large to
  4086. be represented in Microsoft BASIC number
  4087. format. If underflow occurs, the result is
  4088. zero and execution continues without an
  4089. error.
  4090. OM 7 Out of memory
  4091. A program is too large, or has too many FOR
  4092. loops or GOSUBs, too many variables, or
  4093. expressions that are too complicated.
  4094. UL 8 Undefined line
  4095. A nonexistent line is referenced in a GOTO,
  4096. GOSUB, IF...THEN...ELSE, or DELETE statement.
  4097. BS 9 Subscript out of range
  4098. An array element is referenced either with a
  4099. subscript that is outside the dimensions of
  4100. the array or with the wrong number of
  4101. subscripts.
  4102. DD 10 Redimensioned array
  4103. Two DIM statements are given for the same
  4104. array; or, a DIM statement is given for an
  4105. array after the default dimension of 10 has
  4106. been established for that array.
  4107. /0 11 Division by zero
  4108. A division by zero is encountered in an
  4109. expression; or, the ooeration of involution
  4110. results in zero being raised to a negative
  4111. power. Machine infinity with the sign of the
  4112. numerator is supplied as the result of the
  4113. Page A-3
  4114. division, or positive machine infinity is
  4115. supplied as the result of the involution, and
  4116. execution continues.
  4117. ID 12 Illegal direct
  4118. A statement that is illegal in direct mode is
  4119. entered as a direct mode command.
  4120. TM 13 Type mismatch
  4121. A string variable name is assigned a numeric
  4122. value or vice versa; a function that exoects
  4123. a numeric argument is given a string argument
  4124. or vice versa.
  4125. OS 14 Out of string space
  4126. String variables have caused BASIC to exceed
  4127. the amount of free memory remaining.
  4128. Microsoft BASIC will allocate string space
  4129. dynamically, until it runs out of memory.
  4130. LS 15 String too long
  4131. An attempt is made to create a string more
  4132. than 255 characters long.
  4133. ST i6 String formula too complex
  4134. A string expression is too long or too
  4135. complex. The expression should be broken
  4136. into smaller expressions.
  4137. CN 17 Can't continue
  4138. An attempt is made to continue a program
  4139. that
  4140. 1. Has halted due to an error.
  4141. 2. Has been modified during a break in
  4142. execution.
  4143. 3. Does not exist.
  4144. OF 18 Undefined user function
  4145. A USR function is called before the function
  4146. definition (DEF statement) is given.
  4147. 19 No RESUME
  4148. An error handling routine is entered but
  4149. contains no RESUME statement.
  4150. Page A-4
  4151. 20 RESUME without error
  4152. A RESUME statement is encountered before an
  4153. error handling routine is entered.
  4154. 21 Unprintable error
  4155. An error message is not available for the
  4156. error condition which exists.
  4157. 22 Missing operand
  4158. An expression contains an operator with no
  4159. operand following it.
  4160. 23 Line buffer overflow
  4161. An attempt has been made to input a line that
  4162. has too many characters.
  4163. 26 FOR without NEXT
  4164. A FOR statement was encountered without a
  4165. matching NEXT.
  4166. 29 WHILE without WEND
  4167. A WHILE statement does not have a matching
  4168. WEND.
  4169. 30 WEND without WHILE
  4170. A WEND statement was encountered without a
  4171. matching WHILE.
  4172. Disk Errors
  4173. 50 Field overflow
  4174. A FIELD statement is attempting to allocate
  4175. more bytes than were specified for the record
  4176. length of a random file.
  4177. 51 Internal error
  4178. An internal malfunction has occurred in
  4179. Microsoft BASIC. Report to Microsoft the
  4180. conditions under which the message appeared.
  4181. 52 Bad file number
  4182. A statement or command references a file with
  4183. a file number that is not OPEN or is out of
  4184. the range of file numbers specified at
  4185. Page A-5
  4186. initialization.
  4187. 53 File not found
  4188. A LOAD, KILL, or OPEN statement references a
  4189. file that does not exist on the current disk.
  4190. 54 Bad file mode
  4191. An attempt is made to use PUT, GET, or LOF
  4192. with a sequential file, to LOAD a random
  4193. file, or to execute an OPEN statement with a
  4194. file mode other than I, 0, or R.
  4195. 55 File already open
  4196. A sequential output mode OPEN statement is
  4197. issued for a file that is alreac::, open; or a
  4198. FILL statement is given for a file that is
  4199. onen.
  4200. 57 Disk I/O error
  4201. An I/O error occurred on a disk I/O
  4202. operation. It is a fatal error; i.e., the
  4203. operating system cannot recover from the
  4204. error.
  4205. Page A-6
  4206. 58 File already exists
  4207. The filename specified in a NAME statement is
  4208. identical to a filename already in use on the
  4209. disk.
  4210. 61 Disk full
  4211. All disk storage space is in use.
  4212. 62 Input past end
  4213. An INPUT statement is executed after all the
  4214. data in the file has been INPUT, or for a
  4215. null (empty) file. To avoid this error, use
  4216. the EOF function to detect the end-of-file.
  4217. 63 Bad record number
  4218. In a PUT or GET statement, the record number
  4219. is either greater than the maximum allowed
  4220. (32,767) or equal to zero.
  4221. 64 Bad file name
  4222. An illegal form is used for the filename with
  4223. a LOAD, SAVE, KILL, or OPEN statement (e.g.,
  4224. a filename with too many characters).
  4225. 66 Direct statement in file
  4226. A direct statement is encountered while
  4227. LOADing an ASCII-format file. The LOAD is
  4228. terminated.
  4229. 67 Too many files
  4230. An attempt is made to create a new file
  4231. (using SAVE or OPEN) when all 255 directory
  4232. entries are full.
  4233. APPENDIX B
  4234. Mathematical Functions
  4235. Derived Functions
  4236. Functions that are not intrinsic to Microsoft BASIC may be
  4237. calculated as follows.
  4238. Function Microsoft BASIC Equivalent
  4239. SECANT SEC(X)=1/COS(X)
  4240. COSECANT CSC (X) =1/SIN (X)
  4241. COTANGENT COT(X)=1/TAN(X)
  4242. INVERSE SINE ARCSIN(X)=ATN(X/SQR(-X*X+1))
  4243. INVERSE COSINE ARCCOS(X)=-ATN(X/SQR(-X*X+1))+1.5708
  4244. INVERSE SECANT ARCSEC(X)=ATN(X/SQR(X`X-1))
  4245. 4-SGN(SGN(X)-1)*1.5708
  4246. INVERSE COSECANT ARCCSC(X)=ATN(X/SOR(X *X-1))
  4247. 1-(SGN(X)-1)*1.5708
  4248. INVERSE COTANGENT ARCCOT(X)=ATN(X)+1.5706
  4249. HYPERBOLIC SINE SINH(X)=(EXP.00-EXP(-X))/2
  4250. HYPERBOLIC COSINE COSH(X)=.(EXP(X)+EXP(-X))/2
  4251. HYPERBOLIC TANGENT
  4252. TANH(X)=(EXP(X)-EXP(-X))/
  4253. (EXP(X)+EXP(-X))
  4254. HYPERBOLIC SECANT SECH(X),=2/(EXP(X)+EXP(-X))
  4255. HYPERBOLIC COSECANT CSCH(X)2/(EXP(X)-EXP(-X))
  4256. HYPERBOLIC COTANGENT
  4257. COTH(X)=(EXP(X)+EXP(-X))/
  4258. (EXPOO-EXP(-X))
  4259. INVERSE HYPERBOLIC
  4260. SINE ARCSINH(X)=LOG(X+SOR(X*X+1))
  4261. rNVERSE HYPERBOLIC
  4262. COSINE ARCCOSH(X)=LOG(X+SOR(X*X-1))
  4263. INVERSE HYPERBOLIC
  4264. TANGENT ARCTANH(X)=LOG((1+X)/(1-X))/2
  4265. INVERSE HYPERBOLIC
  4266. SECANT ARCSECH(X)=LOGHSIOR(-X*K+1)+1)/X)
  4267. INVERSE HYPERBOLIC
  4268. COSECANT ARCCSCH(X).-LOGHSGN(X)*SOR(X*X+1)+1)/X)
  4269. INVERSE HYPERBOLIC
  4270. COTANGENT ARCCOTH(X)=LOGNX+1)/(X-1))/2
  4271. <blank page>
  4272. APPENDIX C
  4273. ASCII Character Codes
  4274. Dec Hex CHR Dec Hex CHR Dec Hex
  4275. CHR
  4276. 000 00H NUL 043 2BH 086 56H
  4277. V
  4278. 001 err' 01H SOH 044 2CF: r 087 57H
  4279. 002 02H STX 045 2DH - 088 58H
  4280. X
  4281. 003 03H ETX 046 2EH . 089 59H
  4282. I
  4283. 004 Z 04H EOT 047 2FH / 090 5AH
  4284. 005 05H ENO 048 30H 0 091 5BH
  4285. 006 I 06H ACK 049 31H 1 092 5CH
  4286. 007 07H BEL 050 32H 2 093 5DH
  4287. 1
  4288. 003 08H BS 051 331.-1 3 094 5EH
  4289. 009 09H HT 052 34H 4 095 5FH
  4290. 010-I OAH LF 053 3511 5 096 60H
  4291. 011 OBE VT 054 36H 6 097 61H
  4292. a
  4293. 012 OCH FF 055 37H 7 098 62E
  4294. b
  4295. 013 ODE CR 056 38E 8 099 63E
  4296. c
  4297. 01,', OEH SO 057 3911 9 100 64H
  4298. d
  4299. OIL'n OFH SI 053 3A} 101 65H
  4300. 016 10H DLE 059 3311 102 66H
  4301. 017 11H DC1 060 3CH < 103 67H
  4302. a
  4303. 013 12H DC2 061 3DH = 104 68H
  4304. h
  4305. 019 13H DC3 062 3EH > 105 69H
  4306. 020 i 14H DC4 063 3FH ? 106 6AH
  4307. 021 j 15H NAK 064 40H 107 6BH
  4308. 022 k 16H SYN 065 41H A ,,, 108 6CH
  4309. 023 1 17H ETB 066 42H B 109 6DH
  4310. 024 m 18H CAN 067 43H C 110 6EH
  4311. 025 n 19H EM 068 44H D 111 6FH
  4312. 026 o lAH SUB 069 45H E 112 70H
  4313. 027 P 1BH ESCAPE 070 46H F 113 71H
  4314. 028 q 1CH FS 071 47H G 114 72H
  4315. 029 r 1DH GS 072 48H H 115 73H
  4316. 030 s lEH RS 073 49H I 116 74H
  4317. 031 1FH US 074 4AH J 117 75H
  4318. 032 u 20H SPACE 075 4BH K 118 76H
  4319. 033 v 21H ! 076 4CH L 119 77H
  4320. 034 w 22H n 077 4DH M 120 78H
  4321. 035 x 23H 0 078 4EH N 121 79H
  4322. 036 v 24H $ 079 4FH 0 122 7AH
  4323. 03.8 z 26H & 0.81 51H Q 124 7CH
  4324. 039 i 27H i 082 52H R 125 7DH
  4325. 040 1 28H ( 083 53H S 126 7EH
  4326. 041 29H ) 084 54H T 127 7FH
  4327. 042 DEL 2AH * 085 55H U
  4328. Dec=decimal, Hex=hexadecimal (H), CHR=character,
  4329. LF=Line Feed, FF=Form Feed, CR=Carriage Return, DEL=Rubout
  4330. APPENDIX D
  4331. MICROSOFT BASIC RESERVED WORDS
  4332. The following is a list ofreserved words used in Microsoft
  4333. BASIC.
  4334. ABS ERASE LOF RIGHTS
  4335. AND ERL LOG RID
  4336. ASC ERR LPOS RSET
  4337. ATN ERROR LPRINT RUN
  4338. AUTO END LSET SAVE
  4339. CALL EP MERGE SBN
  4340. CDBL FIELD MID$ SIN
  4341. CHAIN FILES $MI<D$ SPACE
  4342. CHR$ FIX MKI$ SPC
  4343. CINT FOR MYS$ SQR
  4344. CLEAR FRE MOD STOP
  4345. CLOSE GET NAME STR$
  4346. COMMON COSUB NEW STRING$
  4347. CONT HEX$ NOT SWAP
  4348. COS IF OCT$ SYSTEM
  4349. CSNG IMP ON TAB
  4350. CVD INP OPENON TAN
  4351. CVI INPUT OPTION THEN
  4352. CVS INKEY$ OR TO
  4353. DATA INPUTt- PEEK TROFF
  4354. DEFDBL INPUTS POKE TRON
  4355. DEFINT INSTR POS
  4356. DEFSNG ENT PPRINT USR
  4357. DEFSTR KILL PRINTli USING VAL
  4358. DEF FN LEFT$ PUT VARPTR
  4359. DEF USR LEN RANDOMIZE WAIT
  4360. DELETE LET READ WEND
  4361. DIM LINE REM WHILE
  4362. EDIT LIST RENUM WRITE
  4363. ELSE LLIST RESET WRITE#
  4364. END LOAD RESTORE XOR
  4365. EOF LOC RESUME
  4366. <blank page>
  4367. INDEX
  4368. ABS .. . 3-2
  4369. Addition 1-10
  4370. ALL . . . 2-4,2-10
  4371. Arctangent 3-3
  4372. Array variables . 1-7,2-10, 2-21
  4373. Arrays 1-7,2-8, 2-13, 2-27
  4374. ASC 3-2
  4375. ASCII codes 3-2,3-4
  4376. ASCII format 2-5,2-53, 2-81
  4377. Assembly language subroutines2-3,2-19, 2-63,3-24 to 3-25
  4378. ATN 3-3
  4379. AUTO 1-2,2-2
  4380. Boolean operators 1-13
  4381. CALL 2-3
  4382. Carriage return 1-3,2-40, 2-45 to 2-46,
  4383. 2-87to 2-89
  4384. Cassette tape 2-8,2-13
  4385. CDBL 3-3
  4386. CHAIN . 2-4,2-10
  4387. Character set 1-3
  4388. CMS 3-4
  4389. CINT 3-4
  4390. CLEAR 2-7
  4391. CLOAD 2-8
  4392. CLOAD* 2-8
  4393. CLOAD? 2-8
  4394. CLOSE 2-9
  4395. Command level 1-1
  4396. COMMON 2-4,2-10
  4397. Concatenation 1-16
  4398. Constants 1-4
  4399. CONT 2-12,2-45
  4400. Control characters 1-4
  4401. Control-A 2-24
  4402. COS 3-5
  4403. C SAVE 2-13
  4404. CSAVE* 2-13
  4405. CSNG 3-5
  4406. CVD . . 3-6
  4407. CI 3-6
  4408. CVS 3-6
  4409. DA TP 2-15,2-78
  4410. DEF FN 2-16
  4411. DEF USR 2-19,3-24
  4412. DEFDBL 1-7,2-18
  4413. DEFINT 1-7,2-18
  4414. DEFSNG 1-7,2-18
  4415. DEFSTR 1-7, 2-18
  4416. DELETE 1-2, 2-4, 2-20
  4417. DIM 2-21
  4418. Direct mode 1-1, 2-38, 2-58
  4419. Division 1-10
  4420. Double precision . 1-6, 2-18, 2-64, 3-3
  4421. EDIT . . . 1-2, 2-22
  4422. Edit mode 1-4, 2-22
  4423. END 2-9, 2-12, 2-26, 2-36
  4424. EOF . 3-6
  4425. ERASE 2-27
  4426. ERL 2-28
  4427. ERR 2-28
  4428. ERROR 2-29
  4429. Error codes 1-17, 2-28 to 2-29, A-1
  4430. Error handling 2-28, 2-58
  4431. Error messages 1-17, A-1
  4432. Error trapping 2-29, 2-79
  4433. Escape 1-3, 2-22
  4434. EXP . . . 3-7
  4435. Exponentiation 1-10, 1-12
  4436. Expressions 1-10
  4437. FIELD 2-31
  4438. FIX 3-7
  4439. FOR...NEXT 2-33
  4440. FRE 3-8
  4441. Functions 1-15, 2-16, 3-1, 3-1
  4442. GET 2-31, 2-35
  4443. GOSUB 2-36
  4444. GOTO 2-36 to 2-37
  4445. HEX$ 3-8
  4446. Hexadecimal 1-5, 3-8
  4447. IF...GOTO 2-38
  4448. IF...THEN 2-28, 2-38
  4449. Ir...THEN...ELSe 2-38
  4450. IN 3-12
  4451. Indirect mode 1-1
  4452. INKEY$ 3-9
  4453. INP 3-9
  4454. INPUT . 2-12, 2-31, 2-40
  4455. INPUT# . . 2-42
  4456. INPUTS . . 3-10
  4457. INSTR . . 3-11
  4458. INT .. . 3-7
  4459. Integer 3-4, 3-7, 3-12
  4460. Integer division 1-11
  4461. ISIS-II . 2-80
  4462. KILL 2-43
  4463. LEFT$ 3-12
  4464. LEN . ....... 3-13
  4465. LET 2-31, 2-44
  4466. Line feed 1-2, 2-40, 2-45 to 2-46,
  4467. 2-88 to 2-89
  4468. LINE INPUT 2-43
  4469. LINE INPUT? 2-46
  4470. Line numbers 1-1 to 1-2, 2-2, 2-77
  4471. Line printer 2-49, 2-51, 2-87, 3-14
  4472. Lines 1-1
  4473. LIST . 1-2, 2-47
  4474. LLIST 2-49
  4475. LOAD 9-50, 2-81
  4476. LOC 3-13
  4477. LOG 3-14
  4478. Logical operators 1-13
  4479. Loops 2-33, 2-86
  4480. LIDOS 2-87, 3-14
  4481. LPRINT 2-51, 2-87
  4482. LPRINT USING . 2-51
  4483. LSET 2-52
  4484. MERGE 2-4, 2-53
  4485. MID$ 2-54, 3-15
  4486. MED'S ....... 3-16
  4487. MKIS 3-16
  4488. MXS$ 3-16
  4489. MOD OPERATOR 1-11
  4490. Modulus arithmetic 1-11
  4491. Multiplication . . 1-10
  4492. NAME ....... 4 2-55
  4493. Negation 1-10
  4494. NEW 2-9, 2-56
  4495. NULL 2-57
  4496. Numeric constants 1-4
  4497. Numeric variables 1-7
  4498. OCT$ 3-17
  4499. Octal 1-5, 3-17
  4500. ON ERROR GOTO 2-58
  4501. ON...GOSUB 2-59
  4502. ON...GOTO 2-59
  4503. ODEN 2-9, 2-31, 2-6C
  4504. OPerators . . 1-10, 1-12 to 1-13, 1-15 to
  4505. OPTION BASE 2-61
  4506. OUT 2-62
  4507. Overflow 1-12, 3-7, 3-23
  4508. Overlay 2-4
  4509. Paper tape
  4510. PEEK 2-63, 3-17
  4511. POKE a 4, . 2-63, 3-17
  4512. POS 2-87, 3-18
  4513. PRINT 2-64
  4514. PRINT USING 2-66
  4515. PRINT? 2-70
  4516. PRINT USING 2-70
  4517. Protected files . 2-81
  4518. PUT 2-31, 2-72
  4519. Random files 2-31, 2-35, 2-43,.2-52,
  4520. 2-60, 2-72, 3-13, 3-16
  4521. Random numbers . . 2-73, 3-19
  4522. RANDOMIZE .. 2-73, 3-19
  4523. READ 2-74, 2-78
  4524. REM 2-76
  4525. RUM 2-5, 2-28, 2-77
  4526. Relational operators . ? 1-12
  4527. Reserved words D-1
  4528. RESTORE 2-78
  4529. RESUME 2-79
  4530. RETURN 2-36
  4531. RIGHT$ 3-18
  4532. RIND 2-73, 3-19
  4533. RSET 2-52
  4534. Rubout 1-3, 1-16, 2-23
  4535. RUN 2-80 to 2-81
  4536. SAVE 2-50, 2-80 to 2-81
  4537. Sequential files 2-42 to 2-43, 2-46, 2-60,
  4538. 2-70, 2-89, 3-6, 3-13
  4539. SGN 3-19
  4540. SIN 3-20
  4541. Single Precision 1-6, 2-18, 2-64, 3-5
  4542. Space requirements for variables 1-8
  4543. SPACES 3-20
  4544. SPC 3-21
  4545. SQR 3-21
  4546. STOP 2-12, 2-26, 2-36, 2-82
  4547. STR$ 3-22
  4548. String constants 1-4
  4549. String functions 3-6, 3-11 to 3-13, 3-15,
  4550. 3-18, 3-22, 3-24
  4551. String operators 1-16
  4552. String space 2-7, 3-8
  4553. String variables 1-7, 2-18, 2-45 to 2-46
  4554. STRING$ . 3-22
  4555. Subroutines 2-3, 2-36, 2-59
  4556. Subscripts . ? ? 1-8, 2-21, 2-51
  4557. Subtraction 1-10
  4558. SWAP .. . 2-83
  4559. TAB 3-23
  4560. Tab 1-3 to 1-4
  4561. TAN 3-23
  4562. TROFF 2-84
  4563. TRON 2-84
  4564. USR . 2-19, 3-24
  4565. VAL 3-24
  4566. Variables 1-6
  4567. VARPTR 3-25
  4568. WAIT . . 2-85
  4569. WEND 2-8 6
  4570. WHILE 2-85
  4571. WIDTH 2-87
  4572. WIDTH LPRINT 2-87
  4573. WRITE 2-88
  4574. WRITE4 2-89