The Secret Guide to Computers |
||
|
||
|
|
Quick BASIC Quick BASIC understands a few more commands than QBASIC. Quick BASIC is available for MS-DOS and for Apple Macintosh computers, but the Apple Macintosh version is inferior. List of differences When you start using Quick BASIC (version 4.5 for MS-DOS), you’ll encounter these differences from QBASIC.… Start BASIC (page 377) When you buy Quick BASIC, it comes on five 5¼-inch floppy disks. Here’s how to copy them to your hard disk: Turn on the computer without any floppy disk in drive A. When you see the C prompt, put Quick BASIC’s first disk (the Setup/Microsoft QB Express Disk) into drive A and type “a:”. The computer will display an A prompt. Type “setup”. The computer will say “QuickBASIC Setup Program”. Press ENTER twice. The computer will say “Easy Setup Menu”. Press the I key. Press ENTER three times. When the computer tells you, put Quick BASIC’s second disk (the Program Disk) into drive A and press ENTER. When the computer tells you, do the same for the remaining Quick BASIC disks. Press ENTER two extra times. The computer will say “QB Express”. Press R then X. You’ll see an A prompt, like this: A:\> Turn off the computer, so you can start fresh. To start using Quick BASIC, turn on the computer without any floppy disk in drive A. When you see the C prompt, type “cd qb45”, like this: C:\>cd qb45 When you press ENTER at the end of that line, the computer will say: C:\QB45> Type “qb” (and press ENTER). The computer will say “Untitled”. (If the computer says “Welcome to QuickBASIC”, press the Esc key.) File menu (page 382) The file menu can be short or long. The short menu offers just 5 choices; the long menu (which is called the full menu) offers 12 choices. Here’s how to switch from short menu to full menu (or back to short): tap the Alt key, then the letter O, then F. Save (page 382) On the file menu, one of the choices is “Save As...”. Another choice, a plain “Save”, appears just if the menu is full instead of short. So before choosing just “Save”, make sure the menu is full. New (page 383) Quick BASIC’s file menu says “New Program” instead of just “New”. Choose “New Program” by pressing the N key. Open (page 383) Quick BASIC’s file menu says “Open Program” instead of just “Open”. Choose “Open Program” by pressing the letter O. Instant open (page 384) Suppose you’ve written a program that has no errors, and you’ve saved the program as JOE.BAS. Try this: while JOE.BAS is on the blue screen, tap the Alt key, then R, then X, then ENTER. That makes the computer create a file called JOE.EXE (and also a file called JOE.OBJ). Then you can run JOE fast by typing “joe” at the C prompt, like this: C:\QB45>joe
Visual BASIC for DOS Visual BASIC for DOS is newer and fancier than QBASIC & Quick BASIC. List of differences When you start using version 2 of Visual BASIC for DOS, you’ll encounter these differences from QBASIC.… Start BASIC (page 377) When you buy Visual BASIC for DOS, it comes on two 3½-inch floppy disks. Here’s how to copy them to your hard disk: Turn on the computer without any floppy in drive A. When you see the C prompt, put Visual BASIC Disk 1 into drive A and type “a:setup”, so the screen looks like this: C:\>a:setup The computer will say “Visual Basic for MS-DOS Setup”. Press ENTER. The computer will say “Type your full name”. Type your full name (or the name of the company that bought Visual BASIC) and press ENTER at the end of it. Press ENTER six more times. The computer will say, “Insert Disk 2”. Insert it into drive A and press ENTER. (If the computer says “WARNING: Setup has found multiple linkers”, press ENTER again.) The computer will say, “To start Microsoft Visual Basic, type VBDOS at the MS-DOS prompt.” Press ENTER. You’ll see a C prompt, like this: C:\VBDOS> Turn off the computer, so you can start fresh. To start using Visual BASIC, turn on the computer without any floppy disk in drive A, so that the computer says: C:\> If you’ve put the DO.BAT file onto your hard disk (as I recommended in the MS-DOS chapter), type “do vbdos”. If you’ve not put DO.BAT onto your hard disk, type “cd vbdos”, then on the line underneath type “vbdos” again (so the lower line says “C:\VBDOS>vbdos”). If the computer says “Visual Basic”, press ENTER. The computer will say “Untitled” and “Project”. While holding down the Ctrl key, press the F10 key. The word “Project” will disappear. File menu (page 382) Visual BASIC’s file menu gives you 14 choices, which are worded differently than QBASIC’s choices. Instead of “Save”, choose “Save File” (by pressing S). Instead of “Save As”,choose “Save File As” (by pressing A). Instead of “Open”, choose “Add File” (by pressing D). Instead of “New”, choose “New Project” (by pressing N). If you print on paper by choosing Print from the file menu (and then pressing ENTER), the printer will eject the paper automatically. Instant open (page 384) Suppose you’ve written a program that has no errors, and you’ve saved the program as JOE.BAS. Try this: while JOE.BAS is on the blue screen, tap the Alt key, then R, then X, then ENTER. That makes the computer create a file called JOE.EXE (and also a file called JOE.OBJ). Then you can run JOE fast by typing “joe” at the C prompt, like this: C:\VBDOS>joe Print (page 446) To print the entire program onto paper (including even the SUB procedures), press Alt then F then P then ENTER. The printer will eject the paper automatically. Error numbers (page 466) In Visual BASIC, error #73 is "Feature unavailable”, and you can make advanced errors numbered from 80 to 480.
GWBASIC Older versions of MS-DOS came with a more primitive BASIC, called GWBASIC. Yes, GWBASIC came with MS-DOS (and PC-DOS) versions 1, 1.1, 2, 2.1, 3, 3.1, 3.2, 3.3, and 4. GWBASIC resembles QBASIC but omits some QBASIC commands and uses a more primitive way to edit your programs. In earlier editions of this book, I explained GWBASIC in detail. In those editions, the BASIC tutorial emphasizes GWBASIC instead of QBASIC; most of the sample programs are written in GWBASIC. If you’re using GWBASIC, get edition 16, 17, 18, 19, or 20. Phone me at 603-666-6644 to find out which of those editions are still available and their prices. List of differences Here’s how GWBASIC differs from QBASIC.… Start BASIC (page 377) Before using GWBASIC, practice using the keyboard, by giving DOS commands or using a word processor. (QBASIC would require you to practice DOS’s edit command, but GWBASIC does not.) The file that makes the computer understand GWBASIC is usually called “GWBASIC.EXE”; but some versions of MS-DOS (and PC-DOS) call it “BASIC.COM” or “BASICA.COM” instead. Some versions of MS-DOS lack the file altogether and can’t do BASIC. To start GWBASIC, try typing: C:\>gwbasic If the computer gripes (by saying “Bad command or file name”), try typing: C:\>basica If the computer still gripes (by saying “Bad command or file name” again), try typing: C:\>basic If the computer still gripes (by saying “Bad command or file name” again), try saying “dos\gwbasic” or “dos\basica” or “dos\basic”. If you don’t have a drive C (because your computer doesn’t have a hard disk), find the floppy that contains GWBASIC.EXE or BASICA.COM or BASIC.COM. Insert that floppy into drive A and say “gwbasic” or “basica” or “basic”. When you get into GWBASIC successfully, the computer will say: Ok (In QBASIC, the screen would turn blue; but in GWBASIC, the screen stays black, with “Ok” appearing in white lettering.) If the computer does not say the word “Ok”, you probably used the wrong version of DOS. Make sure your version of DOS came from your computer’s manufacturer. For example, if IBM built your computer, use IBM’s PC-DOS, not a clone version of MS-DOS. If a clone company built your computer, use your clone’s version of MS-DOS, not IBM’s PC-DOS. Using the wrong version of DOS makes the computer print a strange message, the screen go crazy, or the keyboard stop working. (If your computer’s an IBM PC Junior, buy the BASIC cartridge and put it into the left cartridge slot before you turn the computer on. That cartridge makes the Junior understand CIRCLE, PAINT, PLAY, TIMER, and the BASIC words for disks.) If your Junior is attached to a monitor instead of a TV, type “width 80” after the computer says “Ok”.) Type your program (page 377) Instead of typing this program — CLS PRINT 4 + 2 type this: 10 CLS 20 PRINT 4 + 2 Notice that you must type a number (such as 10 or 20) in front of each program line. For best results, use these numbers: 10, 20, 30, etc. Run your program (page 377) To run your program, press the F2 key (instead of QBASIC’s SHIFT F5). When the computer finishes running the program, the computer will say: Ok Then to see your program again, press the F1 key (or type “list”) and press ENTER. (If your computer’s an IBM PC Junior, you must press the Fn key before pressing F2 or F1.) Faster typing (page 378) When you press ENTER at the end of the line, the computer will secretly convert “cls” into “CLS” and convert “print” and “?” into PRINT. To see the results of the conversion, type: list Why CLS? (page 378) In GWBASIC, saying CLS is less important than in QBASIC. If you wish, omit the CLS line. When I write GWBASIC programs myself, I usually omit the CLS line. Edit your program (page 378) To start a new program, say: new That makes the computer forget about all the lines of your previous program. Then type the new program. To delete just line 20, type this under your program: 20 That makes the computer forget about line 20. To insert a line 15 between lines 10 and 20, type line 15 under your program. When you finish typing that line, the computer will automatically rearrange your program and put the lines in increasing order. To see the rearranged program, say “list”. To edit line 20 (instead of deleting it), use one of the following methods.… Method 1: retype. Under the program, type line 20 all over again, correctly. When the computer notices that you have two lines numbered 20, the computer will take the bottom line 20 seriously and ignore the original line 20. Method 2: edit. Say “edit 20”. That makes the computer show you line 20 again. Use the right-arrow key to move the cursor (blinking underline) to the part of the line you want to correct, then make your corrections. To delete a character: move the cursor to that character, then press the DELETE key. To replace a character: move the cursor to that character, then type the new character you want instead. To insert extra characters in middle of the line: move to where you want extra characters to begin, then press INSERT key, then type extra characters. When you’ve finished correcting the line, press the ENTER key, which tells the computer to take the corrections seriously. Method 3: list. Say “list” (to see the whole program) or “list 20” (to see just line 20). Use the up-arrow key to move the cursor up into line 20. Then use the same editing procedure as if you used method 2. When you’ve finished correcting the line, press the ENTER key, which tells the computer to take the corrections seriously. After pressing the ENTER key, press the up-arrow or down-arrow keys to move to a different line or down to the bottom of the screen. Fix your errors (page 378) If you misspell CLS or PRINT, the computer will say “Syntax error” and show you the errant line. To fix the error, use one of these methods.… Method 1: retype. Press the ENTER key immediately. Then retype the errant line (and press ENTER again at the end of your retyping). Method 2: edit. Press the left-arrow key until the cursor is at the beginning of the line’s bad part. Then fix the line by retyping the bad part. Then press ENTER. Decimals for big answers (page 379) GWBASIC does not require you to use decimals for big answers. To multiply 200 by 300, you can say just “PRINT 200 * 300”; you do not need to say “PRINT 200 * 300.0”. Print on paper (page 382) If your computer doesn’t have a PRINT SCREEN key, do a screen dump by pressing the PrtSc key while holding down the SHIFT key. (If your computer’s an IBM PC Junior, do a screen dump by pressing the Fn key, then the PrtSc key.) WIDTH 40 (page 382) After running a program that says WIDTH 40, you can return to a normal screen by saying: width 80 File menu (page 382) GWBASIC doesn’t have a file menu. Instead of using a file menu, type these commands: Command Meaning list Show you what program is in the RAM chips. llist Copy the program onto paper. save "joe" Copy the program onto your hard disk, and name the program “JOE.BAS”. files Show you a directory of all the files that are on the hard disk. new Erase the program from the RAM chips. load "joe" Copy the program JOE.BAS from your hard disk to the RAM chips. run "joe" Copy the program JOE.BAS from your hard disk to the RAM chips and run it. system Stop using GWBASIC. Make the computer say “C:\>”. So when you finish using GWBASIC, say: system Instant open (page 384) Suppose you’ve saved a GWBASIC program called JOE. To use JOE, say: C:\>gwbasic joe That makes the computer use GWBASIC and instantly run JOE. Moreover, if JOE’s bottom line says SYSTEM, the computer will automatically exit from GWBASIC when JOE finishes running. SLEEP (page 384) GWBASIC doesn’t understand SLEEP. Instead of saying — 30 SLEEP say: 30 A$ = INPUT$(1) Instead of saying — 30 SLEEP 6 say: 30 T = TIMER 35 IF TIMER < T + 6 THEN GOTO 35 DO…LOOP (page 386) GWBASIC doesn’t understand DO or LOOP. Replace the DO by an apostrophe, and replace the LOOP by a GOTO that says to go to the line containing the apostrophe. So instead of saying — 20 DO 30 PRINT "love" 40 LOOP say: 20 ' 30 PRINT "love" 40 GOTO 20 (If your computer’s an IBM PC Junior, here’s how to abort a program: press the Fn key, then the BREAK key.) Decimal numbers (page 387) GWBASIC does not let a line number include a decimal point. GOTO (page 388) GWBASIC doesn’t let you name the lines: you can’t make a line be named JOE, and you can’t say GOTO JOE. Though you can’t say GOTO JOE, you can say GOTO 10. Lines must be numbered, not named. Variables page 389) When you list the program, the computer will automatically capitalize all variables: x will become X. Long variable names (page 391) When you list the program, the computer will automatically capitalize all variables: profit.in.1996 will become PROFIT.IN.1996. Multi-line IF (page 395) GWBASIC doesn’t understand multi-line IF. Use a single-line IF instead. You can make the single-line IF be up to 255 characters long, even though the screen’s just 80 characters wide. When you reach the screen’s right margin, continue typing: the extra characters will appear underneath. Don’t press ENTER until you’ve typed the entire single-line IF. Here’s a long single-line IF: 30 IF AGE < 18 THEN PRINT "You are still a minor": PRINT "Ah, the joys of youth" ELSE PRINT "You are an adult": PRINT "We can have adult fun" ELSEIF (page 395) Since GWBASIC doesn’t understand multi-line IF, GWBASIC doesn’t understand ELSEIF. Use a single-line IF instead. In the middle of the single-line IF, you can say ELSE IF. Put a space between the ELSE and the IF. Here’s a single-line IF that contains ELSE IF: 30 IF AGE < 18 THEN PRINT "You're a minor" ELSE IF AGE < 100 THEN PRINT "You're a typical adult" ELSE IF AGE < 125 THEN PRINT "You're a centenarian" ELSE PRINT "You're a liar" SELECT (page 396) GWBASIC doesn’t understand SELECT. Instead, say IF and ELSE IF. For example, instead of saying — 30 SELECT CASE A$ 40 CASE "fine" 50 PRINT "That's good!" 60 CASE "lousy" 70 PRINT "Too bad!" 80 CASE ELSE 90 PRINT "I feel the same way" 100 END SELECT say: 30 IF A$ = "fine" THEN PRINT "That's good!" ELSE IF A$ = "lousy" THEN PRINT "Too bad!" ELSE PRINT "I feel the same way" Different relations (page 398) If you accidentally say “=<” instead of “<=”, your program will still work. The GWBASIC understands and accepts “=<” and won’t bother turning it into “<=”. EXIT DO (page 399) Since GWBASIC doesn’t understand DO, it doesn’t understand EXIT DO. Instead of saying EXIT DO, tell the computer to GOTO the line under the loop. For example, instead of saying — 30 DO 40 INPUT "What's my favorite color"; GUESS$ 50 IF GUESS$ = "pink" THEN EXIT DO 60 PRINT "No, that's not my favorite color. Try again!" 70 LOOP 80 PRINT "Congratulations! You discovered my favorite color." say: 30 ' 40 INPUT "What's my favorite color"; GUESS$ 50 IF GUESS$ = "pink" THEN GOTO 80 60 PRINT "No, that's not my favorite color. Try again!" 70 GOTO 30 80 PRINT "Congratulations! You discovered my favorite color." LOOP UNTIL (page 399) Since GWBASIC doesn’t understand DO, it doesn’t understand LOOP UNTIL. Instead of saying LOOP UNTIL, use an IF. For example, instead of saying — 30 DO 40 PRINT "You haven't guessed my favorite color yet!" 50 INPUT "What's my favorite color"; GUESS$ 60 LOOP UNTIL GUESS$ = "pink" say: 30 ' 40 PRINT "You haven't guessed my favorite color yet!" 50 INPUT "What's my favorite color"; GUESS$ 60 IF GUESS$ <> "pink" THEN GOTO 30 END, STOP, or SYSTEM (page 408) Here’s how END, STOP, and SYSTEM differ from each other: END makes the computer say “Ok”. STOP makes the computer say “Ok” but also tell you which line the computer stopped at. SYSTEM makes the computer say “C:\>”. Syntax errors (page 411) If you type “prind” instead of “print”, or you type extra characters at the end of a line, or you forget to type a matching parenthesis, the computer will say: Syntax error If you try to say PRINT 5 + 2 but forget to type the 2, the computer will say: Missing operand Logic errors (page 411) If you say GOTO 10 but no line is numbered 10, the computer will say: Undefined line number PAUSE key (page 412) If your computer’s an IBM PC Junior, here’s how to pause: press the Fn key, then the PAUSE key. F keys (page 412) GWBASIC uses the F keys completely differently: To LIST the program, press F1 then ENTER. To RUN the program, press F2. To LOAD the program, press F3, then type the program’s name, then press ENTER. To SAVE the program, press F4, then type the program’s name, then press ENTER. Each line in your GWBASIC program must begin with a line number. If you type a line that does not begin with a line number, the computer will run that line immediately when you press the ENTER key at the end of the line. For example, if you say — PRINT 4 + 2 the computer will print the answer (6) immediately when you press the ENTER key at the end of the line. The only way to create a breakpoint is to put a STOP line into your program. Bottom line (page 420) The screen’s bottom line normally contains a message reminding you that F1 is LIST, F2 is RUN, F3 is LOAD, F4 is SAVE, etc. To make that message disappear, say — key off or write a program containing a line saying KEY OFF. After saying KEY OFF, you can give a LOCATE command that puts info on line 25. For example, this program puts an “x” at the screen’s bottom right corner: 10 KEY OFF 20 LOCATE 25, 80: PRINT "x"; Whenever your want the bottom line’s message to reappear, say: key on Screen modes (page 420) If you’re using DOS 1, 1.1, 2, 2.1, or 3, you must use screen mode 0, 1, or 2. If you’re using DOS 3.1 or 3.2, you must use screen mode 0, 1, 2, or 3. If you’re using DOS 3.3 or higher, you can use any screen mode from 0 to 10. GWBASIC doesn’t understand screen modes 11, 12, or 13. Screen mode 10 works just on monochrome monitors. If you’re using DOS 3.3 or higher with an EGA or VGA color monitor, choose screen mode 9. If your computer’s an IBM PC Junior, you can use screen modes 0, 1, and 2, plus the following special versions of modes 3, 4, 5, and 6: PC Junior mode Pixels Colors 3 160 by 200 16 4 320 by 200 4 5 320 by 200 16 6 640 by 200 4 Modes 5 and 6 require at least 128K of RAM and require you to give this command beforehand: clear,,,32768 You can put that command in your program. Avoid the bottom (page 421) To avoid any problems about the screen’s bottom line, say KEY OFF at the beginning of your program. Make the top line say KEY OFF and CLS and choose a screen mode, like this: 10 KEY OFF: CLS: SCREEN 9 PLAY (page 422) If you’re using DOS 1 or 1.1, the symbols “>” and “<” don’t work. If your computer’s an IBM PC Junior, try the following experiment.… Turn up the volume on your TV or monitor. Then say: sound on Then make the Junior’s three voices sing simultaneously, like this: play "gab","efg","ccd" While the first voice is singing “gab”, the second voice sings “efg”; the third voice sings “ccd”. Printing the date & time (page 426) If you’re using DOS 1 or 1.1, your computer doesn’t understand TIMER. RANDOMIZE TIMER (page 430) If you’re using DOS 1 or 1.1, instead of saying RANDOMIZE TIMER say RANDOMIZE VAL(RIGHT$(TIME$, 2)). Capitals (page 435) GWBASIC doesn’t understand UCASE$ and LCASE$. Trim (page 436) GWBASIC doesn’t understand LTRIM$ and RTRIM$. General rules (page 438) GWBASIC doesn’t permit long integers. In GWBASIC, all integers are short. If you try to create an integer bigger `than 32767, GWBASIC will make your number be a real number instead of an integer. Biggest real numbers (page 438) The biggest permissible single-precision real number is 1.701411E38. The biggest permissible double-precision real number is 1.701411834604692D38. Accuracy (page 439) GWBASIC handles a double-precision real number’s 16th digit accurately but makes slight mistakes with the 17th digit. Tiniest decimals (page 439) The tiniest single-precision number that the computer can handle is 2.938736E-39. The tiniest double-precision number that the computer can handle is 2.938735877055719D-39. If you try to go tinier than those numbers, the computer will say zero. What to do (page 439) If your program involves trigonometry (SIN, COS, TAN, ATN) or exponents (^, SQR, EXP, LOG), and you want those computations done with double-precision accuracy, you must say “gwbasic/d” (instead of “gwbasic”) or say “basica/d” (instead of “basica”). Prime numbers (page 440) Since GWBASIC doesn’t permit long integers, omit the DEFLNG line (or say DEFINT instead of DEFLNG and use integers no bigger than 32767). SUB procedures (page 445) GWBASIC programmers say “routine” instead of “procedure”. They talk about the “main routine” and “subroutines” instead of a “main procedure” and “SUB procedures”. GWBASIC doesn’t understand the word SUB. Instead of saying — 10 CLS 20 PRINT "We all know..." 30 insult 40 PRINT "...and yet we love you." 1000 SUB insult 1010 PRINT "You are stupid!" 1020 PRINT "You are ugly!" 1030 END SUB say this: 10 CLS 20 PRINT "We all know..." 30 GOSUB 1000 40 PRINT "...and yet we love you." 50 END 1000 PRINT "You are stupid!" 1020 PRINT "You are ugly!" 1030 RETURN Notice that the main routine’s bottom line should say END, and the subroutine’s bottom line should say RETURN. When you say “GOSUB 1000”, the computer does a “GOTO 1000” but also remembers where it came from, so the computer can return there when you say “RETURN”. GWBASIC’s subroutines act like any other lines in the program: the subroutines do not use a separate part of the RAM. For example, if the main routine says “X = 4”, the X will then be 4 in the subroutine also. If the subroutine says “X = 100”, the X will then be 100 in the main routine also. All variables are automatically global and COMMON SHARED, so you don’t need to say so. Subroutines can’t have arguments or parameters. If you say DEFINT A-Z at the beginning of the program, all variables in all routines will be short integers. Loops (page 458) Instead of saying — 30 DO UNTIL EOF(1) 40 INPUT #1, FRIEND$ 50 PRINT FRIEND$ 60 LOOP 70 CLOSE say: 30 IF EOF(1) THEN GOTO 70 40 INPUT #1, FRIEND$ 50 PRINT FRIEND$ 60 GOTO 30 70 CLOSE PUT (page 459) GWBASIC doesn’t understand “STRING * 20”. Instead of saying — 20 DIM RECORD AS STRING * 20 30 OPEN "jim" FOR RANDOM AS 1 LEN = LEN(record) say: 30 OPEN "jim" AS 1 LEN=20: FIELD 1, 20 AS RECORD$ Instead of saying — 40 RECORD = "Love makes me giggle" 50 PUT 1, 7, RECORD say: 40 LSET RECORD$ = "Love makes me giggle" 50 PUT 1, 7 Notice that line 40 begins with the word LSET, and line 50 does not end with the word RECORD. Here’s the rule about LSET: if a variable (such as RECORD$) is in a FIELD statement, you cannot put that variable into an ordinary “=” statement; instead of saying RECORD$ = "Love makes me giggle”, you must say LSET RECORD$ = "Love makes me giggle”. You cannot put the variable into an INPUT statement: instead of saying INPUT RECORD$, you must say INPUT A$ and then LSET RECORD$ = A$. In the OPEN statement, the number after “LEN=“ is called the record length. If you want the record length to be more than 128 (because the string is long), you must warn the computer. For example, to warn the computer that you’ll want a record length of 200, say “gwbasic/s:200” (instead of just “gwbasic”), or say “basica/s:400” (instead of just “basica”). GET (page 459) Instead of saying — 40 GET 1, 7, RECORD say just: 40 GET 1, 7 Multi-field records (page 460) GWBASIC doesn’t understand the word TYPE. Instead of saying — 20 TYPE COMBINATION 30 A AS STRING * 20 40 B AS STRING * 5 50 END TYPE 60 DIM RECORD AS COMBINATION 70 OPEN "jack" FOR RANDOM AS 1 LEN = LEN(record) say: 70 OPEN "jack" AS 1 LEN=25: FIELD 1, 20 AS A$, 5 AS B$ Instead of saying — 80 RECORD.A = "I want turkey on rye" 90 RECORD.B = "yummy" 100 PUT 1, 6, RECORD say: 80 LSET A$ = "I want turkey on rye" 90 LSET B$ = "yummy" 100 PUT 1, 6 Lengths (page 460) Saying “LEN(record)” doesn’t work well. Instead of saying “LEN(record)”, just say the record length. For example, if the record length is 25, say 25. If the record length is 25, the number of records in the file is LOF(1) \ 25. End of the file (page 460) If the record length is 25, and each record consists of part A$ and part B$, these lines print all the records: 100 FOR I = 1 TO LOF(1) \ 25 110 GET 1, I 120 PRINT A$ 130 PRINT B$ 140 NEXT Numeric data (page 460) In a GWBASIC random-access file, each record must consists of strings, not numbers. If you want to store numbers in the file, you must turn the numbers into strings. To turn an integer into a string, use the function MKI$ (MaKe from Integer). It turns the integer into a 2-byte string, even if the integer is long. For example, to turn the integer 17999 into a 2-byte string called A$, say “FIELD 1, 2 AS A$” and say “LSET A$ = MKI$(17999)”. The function MKS$ (MaKe from Single-precision real) turns a real number into a 4-byte string. The function MKD$ (MaKe from Double-precision) turns a double-precision number into an 8-byte string. Suppose you turn a number into a string (by using MKI$, MKS$, or MKD$), and PUT the string into a file, and later GET the string back from the file. You’ll want to convert the string back to a number. Use the function CVI (ConVert to Integer) or CVS (ConVert to Single-precision) or CVD (ConVert to Double-precision). For example, if A$ is a 2-byte string that stands for an integer, you can make the computer print the integer by saying PRINT CVI(A$). LOC (page 460) Instead of saying “PUT 1, 7” or “PUT 1, 8”, you can leave the record’s number blank and say just “PUT 1”. That makes the computer PUT the next record. Saying “PUT 1” has the same effect as saying “PUT 1, LOC(1) + 1”. If you say “GET 1”, the computer will GET the next record. Multiple files (page 460) If you want the computer to handle two random-access files simultaneously, use two OPEN statements. In the first OPEN statement, say “AS 1”; in the second OPEN statement, say “AS 2”. In the first FIELD statement, say “FIELD 1”; in the second FIELD statement, say “FIELD 2”. For the second file, say 2 instead of 1 in the OPEN, FIELD, PUT and GET statements and in the LOF and LOC functions. Error numbers (page 466) In GWBASIC, you can make these errors: # Message # Message 1NEXT without FOR 29WHILE without WEND 2Syntax error 30WEND without WHILE 3RETURN without GOSUB 50FIELD overflow 4Out of DATA 51Internal error 5Illegal function call 52Bad file number 6Overflow 53File not found 7Out of memory 54Bad file mode 8Undefined line number 55File already open 9Subscript out of range 57Device I/O Error 10Duplicate Definition 58File already exists 11Division by zero 61Disk full 12Illegal direct 62Input past end 13Type mismatch 63Bad record number 14Out of string space 64Bad filename 15String too long 66Direct statement in file 16String formula too complex67Too many files 17Can't continue 68Device Unavailable 18Undefined user function 69Communication buffer overflow 19No RESUME 70Permission Denied 20RESUME without error 71Disk not Ready 22Missing operand 72Disk media error 23Line buffer overflow 73Advanced Feature 24Device Timeout 74Rename across disks 25Device Fault 75Path/File Access Error 26FOR without NEXT 76Path not found 27Out of Paper
Other computers I’ve described five BASIC versions: QBASIC Visual BASIC for Windows Quick BASIC Visual BASIC for DOS GWBASIC They work on IBM-compatible computers using PC-DOS or MS-DOS. If your computer is not IBM-compatible or does not use PC-DOS or MS-DOS, it probably uses a more primitive version of BASIC. Those primitive versions are explained in editions 1-20 of this book. For example, those editions explain versions of BASIC for the Mac, Apple 2, Commodore 64, Commodore Vic, Coleco Adam, CP/M computers, and computers made by Atari, Texas Instruments, and Timex/Sinclair. To find out which editions are still available and which ones explain your computer, phone me at 603-666-6644 anytime! |
| all content copyright © 2002 | This website is provided as a community service by StaffASAP, the best Applicant Tracking System in the World! |