home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / gutenburg / guten96e / sgcpv22 / FUN.22A < prev    next >
Text File  |  1996-06-05  |  75KB  |  979 lines

  1.     To program the computer, you must use a language that the computer understands. Most computers understand a language called BASIC, which is a small part of English.
  2.     BASIC was invented by two Dartmouth College professors (John Kemeny and Tom Kurtz) in 1964. Later they improved it. Now BASIC consists of words such as PRINT, INPUT, IF, and THEN.
  3.     Here's how to program the computer by using those BASIC words.
  4.  
  5.                                                                  Microsoft BASIC
  6.     Different computers speak different dialects of BASIC. The most popular dialect was invented in 1975 by a 19-year-old kid, Bill Gates. Since he developed software for microcomputers, he called himself Microsoft and called his BASIC dialect Microsoft BASIC.
  7.     Since Microsoft BASIC is so wonderful, all the popular computer companies paid him to make their computers understand Microsoft BASIC. That's right: IBM, Apple, Commodore, Tandy, Atari, Texas Instruments, and hundreds of other computer companies all had to pay off Bill.
  8.     Microsoft BASIC has become so popular that Bill had to hire hundreds of employees to help him fill all the orders. Microsoft Incorporated has become a multi-billion-dollar company, and Bill has become a famous billionaire, the wealthiest person in America.
  9.  
  10.                                                                  What's QBASIC?
  11.     Over the years, Bill gradually improved Microsoft BASIC. Some computers use old versions of Microsoft BASIC; other computers use his latest improvements.
  12.     Now the most popular versions of Microsoft BASIC is QBASIC. It's a simplification of another version of Microsoft BASIC, called Quick BASIC.
  13.     QBASIC comes free when you buy MS-DOS 5, 6, 6.2, 6.21, or 6.22. It also comes free when you buy IBM PC-DOS 5 (which is similar to MS-DOS 5). QBASIC does not come with IBM PC-DOS 6.1, 6.3, or 7.
  14.     If you're using Windows 95, you can use QBASIC if your computer used to have MS-DOS 5, 6, 6.2, 6.21, or 6.22 or if your copy of Windows 95 came on a CD-ROM disk.                                                                                                                                                                                                                          What's in this chapter?
  15.     This chapter explains how to use QBASIC. The chapter ends with an appendix (on pages 444-449) explaining how other versions of BASIC differ.
  16.     The chapter includes 8 sections:
  17.  
  18.                                             Page
  19.                     Fun
  20.                       Enter BASIC            326
  21.                       Math                    330
  22.                       Strings                332
  23.                       Tricky printing        333
  24.                       File menu                335
  25.                       Become an expert        336
  26.                       Going & stopping        337
  27.                     
  28.                     Using variables
  29.                       What's a variable?        342
  30.                       INPUT                345
  31.                       IF                    350
  32.                       SELECT                352
  33.                       Fancy ``IF'' conditions    355
  34.                       Exiting a ``DO'' loop    357
  35.                       FOR . . . NEXT        358
  36.                       DATA . . . READ        362
  37.                       Variables & constants    370
  38.                       Loop techniques        371
  39.                     
  40.                     Helpful hints
  41.                       Debugging            376
  42.                       Error messages        377
  43.                       Pause key                378
  44.                       F keys                378
  45.                       Apostrophe            379
  46.                     
  47.                     Pretty output
  48.                       Zones                380
  49.                       TAB                    382
  50.                       LOCATE                384
  51.                       Pixels                    384
  52.                       Sounds                387
  53.                       PRINT USING        388
  54.                     
  55.                     Fancy calculations
  56.                       Exponents            390
  57.                       Contrasts                391
  58.                       Clock                    392
  59.                       Stripping                394
  60.                       Random numbers        396
  61.                       Character codes        400
  62.                       String analysis            402
  63.                       Trigonometry            404
  64.                       Types of numbers        405
  65.                     
  66.                     Sub stuff
  67.                       Subscripts                410
  68.                       SUB procedures        415
  69.                     
  70.                     Style
  71.                       Design a program        420
  72.                       Make it efficient        422
  73.                       Test it                422
  74.                       Document it            423
  75.                     
  76.                     Weird features
  77.                       Fancy input            424
  78.                       SWAP                427
  79.                       Sequential data files    432
  80.                       Random access        434
  81.                       Create a database        436
  82.                       SHELL                440
  83.                       ON ERROR GOTO    441
  84.                       Memory cells            443
  85.                       Versions of BASIC    444
  86.     QBASIC's commands, functions, and F keys are explained on these pages:
  87. Command                    What the computer will do            Page    Similar to
  88. BEEP                            hum for a quarter of a second                387    SOUND, PLAY
  89. CASE "fine"                    if SELECTed is ``fine'', do indented lines        352    SELECT, IF
  90. CIRCLE (100, 100), 40        draw a circle at (100, 100) with radius 40        385    LINE, PAINT
  91. CLOSE                            put finishing touches on the data files        419    OPEN
  92. CLS                            clear the screen, so it becomes all black        328    NEW, LOCATE
  93. COMMON SHARED x                make x's box be shared among all procedures    418    DIM SHARED
  94. DATA meat, potatoes            use this list of data: meat, potatoes            362    READ, RESTORE
  95. DATE$ = "01-24-1996"        set the clock/calendar to 01-24-1996            392    TIME$ =
  96. DECLARE SUB insult ()        prepare to use SUB procedure called ``insult''    415    SUB
  97. DEF SEG = 0                    use memory segment #0                        443    POKE
  98. DEFDBL A-Z                    make ordinary variables be double-precision    406    DEFLNG, DEFINT
  99. DEFINT A-Z                    make ordinary variables be short integers        406    DEFLNG, DEFDBL
  100. DEFLNG A-Z                    make ordinary variables be long integers        406    DEFINT, DEFLNG
  101. DIM record AS STRING * 20    make the record be a 20-character string        434    TYPE, DIM
  102. DIM SHARED y$(20)            make y$ be 20 strings that procedures share    418    COMMON, SUB
  103. DIM x$(7)                        make x$ be a list of 7 strings                    410    x =
  104. DO                                    do the indented lines below, repeatedly        338    DO UNTIL, LOOP
  105. DO UNTIL EOF(1)                repeat the indented lines until end of file#1    433    DO, LOOP UNTIL
  106. ELSE                            do indented lines when IF conditions false    351    IF, ELSEIF
  107. ELSEIF age < 100 THEN        do lines when earlier IFs false & age < 100    351    IF, ELSE
  108. END                            skip the rest of the program                    341    STOP, SYSTEM
  109. END IF                            make this the bottom of an IF statement        351    IF, ELSE
  110. END SELECT                    make this the bottom of SELECT statement    352    SELECT, CASE
  111. END SUB                        make this the bottom of a SUB procedure    415    SUB
  112. END TYPE                        make this the bottom of a TYPE statement    434    TYPE
  113. EXIT DO                        skip down to the line that's under LOOP        357    DO, LOOP
  114. EXIT SUB                        skip down to the END SUB line                436    END SUB
  115. FILES                            print the names of all the hard disk's files        440    SHELL, NAME
  116. FOR x = 1 TO 20                repeat the indented lines, 20 times            358    NEXT, DO
  117. GET 1, 7, record                from file#1, get the 7th record                434    PUT, INPUT #1
  118. GOTO 10                        skip to line 10 of the program                341    DO, EXIT DO
  119. IF y < 18 THEN PRINT "m"    if y is less than 18, print an ``m''                350    ENDIF, ELSE
  120. INPUT "What name"; n$        ask ``What name?'' and get answer n$            345    LINE INPUT
  121. INPUT #1, a$                    input from file#1 the value of a$                432    INPUT
  122. KILL "joe.bas"                erase the file JOE.BAS from your hard disk    440    FILES, SHELL
  123. LINE (0, 0)-(100, 100)        draw a line from (0, 0) to (100, 100)            385    PSET, CIRCLE
  124. LINE INPUT "Type it"; n$    say ``Type it'' and grab whole line as input    425    INPUT
  125. LOCATE 3, 7                    move to the screen's 3rd line, 7th position    384    PRINT, CLS
  126. LOOP                            make this the bottom line of a DO loop        338    LOOP UNTIL
  127. LOOP UNTIL guess$ = "p"    do the loop repeatedly, until guess$ is ``p''    357    LOOP, DO UNTIL
  128. LPRINT 2 + 2                    print, onto paper, the answer to 2 + 2        334    PRINT
  129. MID$(a$, 2)="owl"            change the middle of a$ to ``owl''                402    x =
  130. NAME "joe.bas" AS "f.bas"    find the file JO.BAS and rename it F.BAS    440    FILES, SHELL
  131. NEXT                            make this the bottom line of a FOR loop        358    FOR
  132. ON ERROR GO TO 1000            if the lines below cause errors, go to 1000        441    RESUME
  133. OPEN "jo" FOR OUTPUT AS 1    create a data file called ``JO''; output to it    432    CLOSE
  134. PAINT (100, 101)                fill in the shape that surrounds (100, 101)        385    LINE, CIRCLE
  135. PLAY "c d g# b- a"            play this music: C, D, G sharp, B flat, A        387    SOUND, BEEP
  136. POKE 1047, 224                into memory cell #1047, put 224                443    DEF SEG, x =
  137. PSET (100, 100)                make pixel (100, 100) turn white                385    SCREEN, LINE
  138. PRINT 4 + 2                    print the answer to 4 + 2                    328    PRINT USING
  139. PRINT USING "##.#"; x        print x, rounded to one decimal place            388    PRINT
  140. PRINT #1, "eat"                print onto file#1 the word ``eat''                432    PRINT, LPRINT
  141. PUT 1, 7, record                in file#1, change the 7th record                434    GET, PRINT #1
  142. RANDOMIZE TIMER                make random numbers be unpredictable        396    x =
  143. READ a$                        get a string from the DATA and call it a$    362    DATA, RESTORE
  144. RESTORE 10                    skip to line 10 of the DATA                    367    READ, DATA
  145. RESUME 10                        end the error trap, by going to line 10        441    ON ERROR GO TO
  146. SCREEN 12                        use video mode 12 so you get VGA graphics    385    PSET, WIDTH
  147. SELECT CASE a$                analyze a$ to select a case from list below        352    END SELECT, IF
  148. SHELL "ver"                    do this DOS command: ``ver''                440    SYSTEM
  149. SOUND 440, 18.2                make a sound of 440 hertz, for 1 second        387    PLAY, BEEP
  150. SLEEP                            pause until you press a key                    337    FOR
  151. STOP                            skip rest of program; show the blue screen    369    END, SYSTEM
  152. SUB insult                    make the lines below define ``insult''            415    END SUB
  153. SWAP x, y                        make x and y swap values with each other    427    x =
  154. SYSTEM                            skip rest of program; try to show ``C:\>''        369    END, STOP
  155. TIME$ = "13:45:07"            set the clock to 7 seconds after 13:45            392    DATE$ =
  156. TYPE combination                make ``combination'' be a type of variable        434    END TYPE
  157. WIDTH 40                        on screen make each character twice as wide    334    CLS
  158. x = 47                            make x stand for the number 47                342    INPUT, POKE
  159. Function                Meaning                    Value        Page    Similar to
  160. ABS(-3.89)                absolute value of -3.89            3.89            394    SGN
  161. ASC("A")                    ASCII code number for A        65                401    CHR$
  162. ATN(1) / degrees            arctangent of 1, in degrees        45                404    TAN
  163. CHR$(164)                    character whose code# is 164    ``¤''            400    ASC
  164. CINT(3.89)                round to nearest integer            4                394    INT, FIX
  165. COS(60 * degrees)        cosine of 60 degrees            .5                404    SIN, TAN
  166. DATE$                        today's date                    varies            392    TIME$
  167. EOF(1)                        test whether at end of file#1    varies            433    LOF, ERR
  168. ERR                        the error's code number            varies            442    EOF
  169. EXP(1)                        e raised to the first power        2.718282        390    LOG, SQR
  170. FIX(3.89)                    erase digits after decimal point    3                394    INT, CINT
  171. INPUT$(4)                    4 characters that are input        varies            425    INSTR
  172. INSTR("needed", "ed")    position of ``ed'' in ``needed''    3                403    other INSTR
  173. INSTR(4,"needed","ed")    search from the 4th character    5                403    other INSTR
  174. INT(3.89)                    round down to a lower integer    3                394    FIX, CINT
  175. LCASE$("We love")        lower case; uncapitalize            ``we love''        402    UCASE$
  176. LEFT$("smart", 2)        left 2 characters of ``smart''        ``sm''            402    RIGHT$, MID$
  177. LEN("smart")                length of ``smart''                5                402    RIGHT$, MID$
  178. LOC(1)                        location of record in file#1        varies            435    LOF
  179. LOF(1)                        length of file#1, in bytes        varies            433    EOF
  180. LOG(2.718282)            logarithm base e                1                391    EXP
  181. LTRIM$("   Sue Smith")    delete beginning spaces            ``Sue Smith''    403    RTRIM$
  182. MID$("smart", 2)            begin at the 2nd character        ``mart''            402    other MID$
  183. MID$("smart", 2, 3)        begin at the 2nd, take 3            ``mar''            402    other MID$
  184. PEEK(49837)                peek at memory cell #49837        varies            443    TIMER, RND
  185. RIGHT$("smart", 2)        rightmost 2 characters            ``rt''            402    LEFT$, MID$
  186. RND                        random decimal                varies            396    TIMER
  187. RTRIM$("Sue Smith   ")    delete ending spaces            ``Sue Smith''    403    LTRIM$
  188. SGN(-3.89)                sign of -3.89                    -1                394    ABS, FIX
  189. SIN(30 * degrees)        sine of 30 degrees                .5                404    COS, TAN
  190. SQR(9)                        square root of 9                3                390    EXP, LOG
  191. STR$(81.4)                turn 81.4 into a string            `` 81.4''            403    VAL
  192. STRING$(5, "b")            a string of 5 b's                    ``bbbbb''        403    other STRING$
  193. STRING$(5, 98)            98th ASCII character, 5 times    ``bbbbb''        403    other STRING$
  194. TAN(45 * degrees)        tangent of 45 degrees            1                404    ATN
  195. TIME$                        current time of day                varies            392    TIMER, DATE$
  196. TIMER                        # of seconds since midnight        varies            392    TIME$, DATE$
  197. UCASE$("We love")        capitalize ``We love''            ``WE LOVE''    402    LCASE$
  198. VAL("52.6")                remove the quotation marks        72.6            403    STR$
  199.  
  200. F key    Name    What the computer will do    Page
  201. F2            SUB        show a different SUB                415
  202. F4            View        switch between blue & black screens    329
  203. F5            Continue    continue running the program        379
  204. SHIFT F5    Run        run the entire program                328
  205. F6            Immediate    move to & from immediate window    378
  206. F7            Above        run the program down to here        379
  207. F8            Step        run one more line of the program    379
  208. F9            Breakpoint    create or destroy a red breakpoint    378
  209.  
  210.                                                                                           Start QBASIC
  211.     To start using QBASIC, turn on the computer without any floppy in drive A.
  212.     Make sure the screen shows this standard C prompt:
  213. C:\>
  214. (To make the screen show it, follow the instructions on pages 100-101 of the MS-DOS chapter. Those instructions work even if you're using Windows 3 or 3.1 or 3.11 or 95. For more details about making Windows 95 show the C prompt, read page 160's ``DOS Commands''. For more details about making earlier versions of Windows show the C prompt, read page 148's ``Choose from a menu''.)
  215.     To start using QBASIC, type ``qbasic'' after the C prompt, so your screen looks like this:
  216. C:\>qbasic
  217. When you press the ENTER key at the end of that line, see what happens!
  218.     If you're lucky, the screen will turn blue and the computer will say:
  219. Welcome to MS-DOS QBASIC
  220.     If you're unlucky, the computer will gripe by saying ``Bad command or file name''. To find out why the computer is griping, type ``ver'' after the C prompt. Then the computer will tell you which version of DOS it's using. To run QBASIC, you must buy DOS version 5, 6, 6.2, or 6.22 (since QBASIC is not included with DOS versions 6.1 or 6.3 or 7), or buy the CD-ROM version of Windows 95 and copy QBASIC from that CD-ROM to your hard disk as follows: Insert the Windows 95 CD-ROM disk. If that disk's window is on the screen, close the window by clicking its X box. Make sure the computer says ``C:\>'' (by following the instructions on page 160). Then type ``copy d:other\oldmsdos\qbasic.* windows\command''. (After the asterisk, make sure you put a space then ``windows\command''. If your CD-ROM drive is called ``drive E'' instead of ``drive D'', type ``e:'' instead of ``d:''.)
  221. Then try again to type ``qbasic'' after the C prompt.
  222.     After the computer says ``Welcome to MS-DOS QBASIC'', press the Esc key (which is at the keyboard's top left corner).
  223.  
  224.                                                                                                                                                                                                                                                     Type your program
  225.     Now you're ready to type your first program!
  226.     For example, type this program:
  227. CLS
  228. PRINT 4 + 2
  229.     Here's how. Type CLS, then press the ENTER key at the end of that line. Type PRINT 4 + 2 (and remember to hold down the SHIFT key to type the symbol +), then press the ENTER key at the end of that line.
  230.     Notice that you must press the ENTER key at the end of each line.
  231.     A program is a list of commands that you want the computer to obey. The sample program you typed contains two commands. The first command (CLS) tells the computer to CLear the Screen, so the computer will erase the screen and the screen will become blank: entirely black! The next command (PRINT 4 + 2) tells the computer to do some math: it tells the computer to compute 4 + 2, get the answer (6), and print the answer on the screen.
  232.  
  233.                                                                                                                                                                                                                                                     Run your program
  234.     To make the computer obey the program you wrote, do this: while holding down the SHIFT key, tap the F5 key. That tells the computer to run the program: the computer will run through the program and obey all the commands in it.
  235.     The computer will begin by obeying the CLS command. The computer will clear the screen and make the screen become all blank, all black.
  236.     Then the computer will obey the PRINT 4 + 2 command. The computer will print this answer onto your screen:
  237.  6
  238.     Congratulations! You've written your first program! You've programmed the computer to compute the answer to 4 + 2! You've become a programmer! Now you can put on your resumŵ: ``programmer!''     When you finishing admiring the computer's answer, press the F4 key. That makes the screen change: instead of showing the computer's answer, the screen will turn blue and show your program again:
  239. CLS
  240. PRINT 4 + 2
  241.     If you'd like to peek at the answer again (which is 6 on a black screen), press the F4 key again. When you finish peeking at the answer, press the F4 key again to view the program again (CLS and PRINT 4 + 2 on a blue screen).
  242.     So here are the rules:
  243. To run the program (and put the answer on a black screen), press SHIFT with F5.
  244. To view the blue screen again ___ or switch back to the black screen again ___ press F4.
  245.  
  246.                                                                                           Faster typing
  247.     While typing the program, you don't need to capitalize computer words such as CLS and PRINT: the computer will capitalize them automatically when you press ENTER at the end of the line.
  248.     While typing that program, put a blank space after the word PRINT to separate the ``PRINT'' from the 4. But you don't need to put spaces next to the + sign, since the computer will automatically insert those spaces when you press ENTER at the end of the line.
  249.     Instead of typing ``PRINT'' or ``print'', you can type just a question mark. When you press the ENTER key at the end of the line, the computer will replace the question mark by the word PRINT, and the computer will put a blank space after it.
  250.     So instead of typing PRINT 4 + 2, you can type just this:
  251. ?4+2
  252.     Think of the question mark as standing for this word:
  253. What's
  254. If you want to ask the computer ``What's 4+2'', type this:
  255. ?4+2
  256. When you run the program, the computer will print the answer, 6.
  257.  
  258.                                                                                             Why CLS?
  259.     The program's top line (CLS) tells the computer to erase the screen before printing the answer (6).
  260.     If you forget to make the program's top line say CLS, the computer will forget to erase the screen. The computer will still print the answer (6), but that answer will appear underneath a transcript of previous chit-chat that occurred between you and the computer. That transcript is distracting and confusing. CLS erases it.
  261.  
  262.                                                                                         Edit your program
  263.     After you've typed your program, try typing another one. For example, create a program that makes the computer print the answer to 79 + 2. To do that, make this program appear on the screen:
  264. CLS
  265. PRINT 79 + 2
  266.     To make that program appear, just edit the program you typed previously (which said PRINT 4 + 2). To edit, use the arrow keys to move to the character you want to change (which was the 4), delete that character (4) by pressing the DELETE key, then type the characters you want instead (79).
  267.     While editing, use these tricks. . . . 
  268. To delete a character:
  269. move the cursor (blinking underline) to that character, then press the DELETE key.
  270.  
  271. To delete SEVERAL characters:
  272. move to the first character you want to delete, then hold down the DELETE key awhile.
  273.  
  274. To delete AN ENTIRE LINE:
  275. move to that line; then while holding down Ctrl key, tap the Y key.
  276.  
  277. To INSERT A NEW LINE between two lines:
  278. move to the beginning of the lower line; then while holding down Ctrl key, tap the N key.
  279.     If you've edited the program successfully, the screen shows just the new program ___ 
  280. CLS
  281. PRINT 79 + 2
  282. and you do not see the old program anymore.
  283.     When you've finished editing the program, run it (by pressing SHIFT with F5 again). Then the computer will print the answer:
  284.  81
  285.  
  286.                                                                                                                                                                                                                                                      Fix your errors
  287.     What happens if you misspell a computer word, such as CLS or PRINT? For example, what happens if you accidentally say PRIMPT instead of PRINT?
  288.     When you run the program (by pressing SHIFT with F5), the computer tries to run each line of your program. If the computer comes to a misspelled computer word (such as PRIMPT), the computer highlights your misspelling (by showing it in blue letters against a white background) and says:
  289. Syntax error
  290. Press the ENTER key, then fix your error, then try again to run the program (by pressing SHIFT with F5 key again).     This command makes the computer add 4 + 2:
  291. PRINT 4 + 2
  292. Put that command into a program (whose top line should be CLS). When you run the program (by pressing SHIFT with F5), the computer will print the answer:
  293.  6
  294.     If you want to subtract 3 from 7, type this command instead:
  295. PRINT 7 - 3
  296. (When typing the minus sign, do not press the SHIFT key.) The computer will print:
  297.  4
  298.     You can use decimal points and negative numbers. For example, if you type this ___ 
  299. PRINT -26.3 + 1
  300. the computer will print:
  301. -25.3
  302.  
  303.                                                                  Multiplication
  304.     To multiply, use an asterisk. So to multiply 2 by 6, type this:
  305. PRINT 2 * 6
  306. The computer will print:
  307.  12
  308.  
  309.                                                                     Division
  310.     To divide, use a slash. So to divide 8 by 4, type this:
  311. PRINT 8 / 4
  312. The computer will print:
  313.  2
  314.                                                                                                                                                                                                                            Huge & tiny numbers
  315.     When dealing with huge and tiny numbers, be careful!
  316.     Avoid commas Do not put commas in big numbers. To write four million, do not write 4,000,000; instead, write 4000000.
  317.     The symbol # If you type a long number (such as 7000000000 or 273.85429), the computer might automatically put the symbol # afterwards. That's the computer's way of reminding itself that the number is long and must be treated extra carefully!
  318.     Use decimals for big answers The computer sometimes has difficulty handling answers bigger than 32 thousand. To avoid difficulty, put a decimal point in any problem whose answer might be bigger than 32 thousand.
  319.     For example, suppose you want the computer to multiply 200 by 300. Since the answer to that problem is 60 thousand, which is bigger than 32 thousand, you should put a decimal point in that problem. But suppose you forget to insert a decimal point, and you say just this:
  320. CLS
  321. PRINT 200 * 300
  322. the computer will complain by saying:
  323. Overflow
  324. When the computer says ``Overflow'', reply by pressing the ENTER key, then fix your program by inserting a decimal point, like this ___ 
  325. PRINT 200 * 300.0
  326. or like this ___ 
  327. PRINT 200 * 300.
  328. When you finish typing that line (and press ENTER afterwards), the computer will do something strange: it will turn the ``.0'' or ``.'' into an exclamation point, so the line looks like this:
  329. PRINT 200 * 300!
  330. When you run the program, the computer will print the right answer:
  331.  60000
  332.     Notice that if you type a decimal point at the end of a number, the computer usually puts an exclamation point (!) at the end of the number. If the number is long, the computer puts a number sign (#) instead of an exclamation point.     E notation If the computer's answer is huge (more than a million) or tiny (less than .01), the computer might print an E in the answer. The E means ``move the decimal point''.
  333.     For example, suppose the computer says the answer to a problem is:
  334.  8.516743E+12
  335. The E means, ``move the decimal point''. The plus sign means, ``towards the right''. Altogether, the E+12 means, ``move the decimal point towards the right, 12 places.'' So look at 8.516743, and move the decimal point towards the right, 12 places; you get 8516743000000.
  336.     So when the computer says the answer is 8.516743E+12, the computer really means the answer is 8516743000000, approximately. The exact answer might be 8516743000000.2 or 8516743000000.79 or some similar number, but the computer prints just an approximation.
  337.     Suppose your computer says the answer to a problem is:
  338.  9.23E-06
  339. After the E, the minus sign means, ``towards the left''. So look at 9.23, and move the decimal point towards the left, 6 places. You get:
  340. .00000923
  341. So when the computer says the answer is 9.23E-06, the computer really means the answer is:
  342. .00000923
  343.     You'll see E notation rarely: the computer uses it just if an answer is huge (many millions) or tiny (tinier than .01). But when the computer does use E notation, remember to move the decimal point!
  344.     D notation If the answer's a long number, the computer usually prints a D instead of an E. Like the E, the D means ``move the decimal point''.
  345.     The highest number The highest number the computer can handle well is about 1E38, which is 1 followed by 38 zeros, like this:
  346. 100000000000000000000000000000000000000
  347. If you try to go much higher, the computer will either gripe (by saying ``Overflow'') or use D notation (which goes up to about 1D308).
  348.     The tiniest decimal The tiniest decimal the computer can handle easily is about 1E-38, which is a decimal point followed by 38 digits, 37 of which are zeros, like this:
  349. .00000000000000000000000000000000000001
  350. If you try to go much tinier, the computer will either say 0 or use D notation (which goes down to about 1D-323).                                                                                                                                                                                                                            Order of operations
  351.     What does ``2 plus 3 times 4'' mean? The answer depends on who you ask.
  352.     To a clerk, it means ``start with 2 plus 3, then multiply by 4''; that makes 5 times 4, which is 20. But to a scientist, ``2 plus 3 times 4'' means something different: it means ``2 plus three fours'', which is 2 + 4 + 4 + 4, which is 14.
  353.     Since computers were invented by scientists, computers think like scientists. If you type ___ 
  354. PRINT 2 + 3 * 4
  355. the computer will think you mean ``2 plus three fours'', so it will do 2 + 4 + 4 + 4 and print this answer:
  356.  14
  357. The computer will not print the clerk's answer, which is 20. So if you're a clerk, tough luck!
  358.     Scientists and computers follow this rule: do multiplication and division before addition and subtraction. So if you type ___ 
  359. PRINT 2 + 3 * 4
  360. the computer begins by hunting for multiplication and division. When it finds the multiplication sign between the 3 and the 4, it multiplies 3 by 4 and gets 12, like this:
  361. PRINT 2 + 3 * 4
  362.  
  363.            12
  364. So the problem becomes 2 + 12, which is 14, which the computer prints.
  365.     For another example, suppose you type:
  366. PRINT 10 - 2 * 3 + 72 / 9 * 5
  367. The computer begins by doing all the multiplications and divisions. So it does 2 * 3 (which is 6) and does 72 / 9 * 5 (which is 8 * 5, which is 40), like this:
  368. PRINT 10 - 2 * 3 + 72 / 9 * 5
  369.  
  370.              6        40
  371. So the problem becomes 10 - 6 + 40, which is 44, which is the answer the computer prints.
  372.     Parentheses  You can use parentheses the same way as in algebra. For example, if you type ___ 
  373. PRINT 5 - (1 + 1)
  374. the computer will compute 5 - 2 and print:
  375.  3
  376.     You can put parentheses inside parentheses. If you type ___
  377. PRINT 10 - (5 - (1 + 1))
  378. the computer will compute 10 - (5 - 2), which is 10 - 3, and will print:
  379.  7
  380.     Let's make the computer fall in love. Let's make it say, ``I love you''.
  381.     Type this program:
  382. CLS
  383. PRINT "I love you"
  384.     Here's how to type the second line. Begin by typing the word PRINT. Then type a blank space (by pressing the SPACE bar). Then type a quotation mark, but be careful: to type the quotation mark, you must hold down the SHIFT key. Then type these words: I love you. Then type another quotation mark. At the end of that line, press the ENTER key.
  385.     When you run the program (by pressing SHIFT with F5), the computer will obey your command; it will print:
  386. I love you
  387.     You can change the computer's personality. For example, if you give this command ___ 
  388. PRINT "I hate you"
  389. the computer will reply:
  390. I hate you
  391.     Notice that to make the computer print a message, you must put the message between quotation marks. The quotation marks make the computer copy the message without worrying about what the message means. For example, if you misspell ``I love you'', and type ___ 
  392. PRINT "aieee luf ya"
  393. the computer will still copy the message (without worrying about what it means); the computer will print:
  394. aieee luf ya
  395.  
  396.                                                                                           Faster typing
  397.     Instead of typing ___ 
  398. PRINT "I love you"
  399. you can type just this:
  400. ?"I love you
  401. At the end of that line, when you press the ENTER key, the computer will automatically do three things:
  402. The computer will replace the question mark by the word PRINT.
  403. The computer will put a blank space after PRINT (and before the quotation mark).
  404. The computer will put a quotation mark at the end of the line (to match the other quotation mark).
  405.  
  406.                                                                                              Jargon
  407.     The word ``joy'' consists of 3 characters: J and O and Y. Programmers say that the word ``joy'' is a string of 3 characters.
  408.     A string is any collection of characters, such as ``joy'' or ``I love you'' or ``aieee luf ya'' or ``76 trombones'' or ``GO AWAY!!!'' or ``xypw exr///746''. The computer will print whatever string you wish, but remember to put the string in quotation marks.
  409.  
  410.                                                                                      Strings versus numbers
  411.     The computer can handle two types of expressions: strings and numbers. Put strings (such as ``joy'' and ``I love you'') in quotation marks. Numbers (such as 4 + 2) do not go in quotation marks.                                                                                                                                                                                                                                                         Accidents
  412.     Suppose you accidentally put the number 2 + 2 in quotation marks, like this:
  413. PRINT "2 + 2"
  414. The quotation marks make the computer think ``2 + 2'' is a string instead of a number. Since the computer thinks ``2 + 2'' is a string, it copies the string without analyzing what it means; the computer will print:
  415. 2 + 2
  416. It will not print 4.
  417.     Suppose you want the computer to print the word ``love'' but you accidentally forget to put the string ``love'' in quotation marks, and type this instead:
  418. PRINT love
  419. Since you forgot the quotation marks, the computer thinks love is a number instead of a string; but the computer doesn't know what number it is, since the computer doesn't know the meaning of love. Whenever the computer is confused, it either gripes at you or prints a zero. In this particular example, when you run the program the computer will print a zero, like this:
  420.  0
  421. So if you incorrectly tell the computer to proclaim its love, it will say zero.
  422.  
  423.                                                                                                                                                                                                                                                      Longer programs
  424.     You can program the computer say it's madly in love with you!
  425.     Let's make the computer say:
  426. I love you.
  427. You turned me on.
  428. Let's get married!
  429.     To make the computer say all that, just run this program:
  430. CLS
  431. PRINT "I love you."
  432. PRINT "You turned me on."
  433. PRINT "Let's get married!"
  434. To run that program, type it and then press the F5 key. Try it!
  435.     To have even more fun, run this program:
  436. CLS
  437. PRINT "I long"
  438. PRINT 2 + 2
  439. PRINT "U"
  440. It makes the computer print ``I long'', then print the answer to 2+2 (which is 4), then print ``U''. So altogether, the computer prints:
  441. I long
  442.  4
  443. U
  444. Yes, the computer says it longs for you!     Printing can be tricky! Here are the tricks. . . . 
  445.  
  446.                                                                     Indenting
  447.     Suppose you want the computer to print this letter:
  448. Dear Joan,
  449.   Thank you for the beautiful
  450. necktie.  Just one problem--
  451. I don't wear neckties!
  452.               Love,
  453.               Fred-the-Hippie
  454.     This program prints it:
  455. CLS
  456. PRINT "Dear Joan,"
  457. PRINT "  Thank you for the beautiful"
  458. PRINT "necktie.  Just one problem--"
  459. PRINT "I don't wear neckties!"
  460. PRINT "              Love,"
  461. PRINT "              Fred-the-Hippie"
  462.     In the program, each line contains two quotation marks. To make the computer indent a line, put blank spaces AFTER the first quotation mark.
  463.  
  464.                                                                    Blank lines
  465.     Life consists sometimes of joy, sometimes of sorrow, and sometimes of a numb emptiness. To express those feelings, run this program:
  466. Program        What the computer will do
  467. CLS                Clear the screen.
  468. PRINT "joy"        Print ``joy''.
  469. PRINT                Print a blank empty line, underneath ``joy''.
  470. PRINT "sorrow"    Print ``sorrow''.
  471. Altogether, the computer will print:
  472. joy
  473.  
  474. sorrow
  475.  
  476.                                                                    Semicolons
  477.     Run this program:
  478. CLS
  479. PRINT "fat";
  480. PRINT "her"
  481.     The second line, which makes the computer print ``fat'', ends with a semicolon. The semicolon makes the computer print the next item on the same line; so the computer will print ``her'' on the same line, like this:
  482. father
  483.     This program gives you some food for thought:
  484. CLS
  485. PRINT "I love to eat her";
  486. PRINT "ring for dinner";
  487. PRINT "you are the most beautiful fish in the whole sea!"
  488. The program says to print three phrases. Because of the semicolons, the computer tries to print all the phrases onto a single line; but those phrases are too long to all fit on the same line simultaneously! So the computer prints just the first two phrases onto the line and prints the third phrase underneath, like this:
  489. I love to eat herring for dinner
  490. you are the most beautiful fish in the whole sea!
  491.     The next program shows what happens to an evil king on a boat: CLS
  492. PRINT "sin"; "king"
  493. The computer will print ``sin'', and will print ``king'' on the same line, like this:
  494. sinking
  495. Notice that in a PRINT statement, you can type several items (such as ``sin'' and ``king''). You're supposed to type a semicolon between each pair of items; but if you forget to type a semicolon, the computer will type it for you automatically when you press the ENTER key at the end of the line. The computer will also automatically put a blank space after each semicolon.
  496.  
  497.                                                                                                                                                                                                                           Spaces after numbers
  498.     Try typing this command:
  499. PRINT -3; "is my favorite number"
  500. Whenever the computer prints a NUMBER, it prints a blank space afterwards; so the computer will print a blank space after -3, like this:
  501. -3 is my favorite number
  502.   
  503.  space
  504.  
  505.                                                                                                                                                                                                                      Spaces before positive numbers
  506.     This command tells what to put in your coffee:
  507. PRINT 7; "do"; "nuts"
  508. The computer prints 7 and ``do'' and ``nuts''. Since 7 is a number, the computer prints a blank space after the 7. The computer prints another blank space BEFORE every number that's positive; so the computer prints another blank space before the 7, like this:
  509.  7 donuts
  510.  
  511. spaces
  512.     Hey, if you're feeling cool, maybe this command expresses your feelings:
  513. PRINT "the temperature is"; 4 + 25; "degrees"
  514. The computer prints ``the temperature is'', then 4 + 25 (which is 29), then ``degrees''. Since 29 is a positive number, the computer prints a blank space before and after the 29:
  515. the temperature is 29 degrees
  516.                     
  517.                              spaces
  518.  
  519.                                                                                                                                                                                                                         Fix the negative numbers
  520.     Use this command if you're even colder:
  521. PRINT "the temperature is"; 4 - 25; "degrees"
  522. The computer prints ``the temperature is'', then 4 - 25 (which is -21), then ``degrees''. Since -21 is a number, the computer prints a space after it; but since -21 is not positive, the computer does not print a space before it. The computer prints:
  523. the temperature is-21 degrees
  524.                     
  525.                    no space    space
  526.     Yuk! That looks ugly! It would look prettier if there were a space before the -21. To insert a space, put the space inside quotation marks:
  527. PRINT "the temperature is "; 4 - 25; "degrees"
  528.                          
  529.                                  inserted space, before the quotation mark
  530. Then the computer will print:
  531. the temperature is -21 degrees
  532.                   
  533.                       inserted space                                                               Multiple calculations
  534.     By using semicolons, you can make the computer do many calculations at once.
  535.     For example, this command makes the computer do 6+2, 6-2, 6*2, and 6/2, all at once:
  536. PRINT 6 + 2; 6 - 2; 6 * 2; 6 / 2
  537. That makes the computer print the four answers:
  538.  8  4  12  3
  539. The computer prints spaces between the answers, because the computer prints a space after every number (and an additional space before every number that's positive).
  540.  
  541.                                                                  Print on paper
  542.     If you say LPRINT instead of PRINT, the computer will print on paper instead of on your screen.
  543.     For example, if you want the computer to compute 2+2 and print the answer on paper, type this program:
  544. CLS
  545. LPRINT 2 + 2
  546. While typing that program, make sure you type ``LPRINT''. Although ``PRINT'' can be abbreviated by typing ``?'', ``LPRINT'' cannot be abbreviated by typing ``L?''; you must type the word ``LPRINT'' in full.
  547.     When you run that program (by putting paper into the printer, turning the printer on, and pressing the F5 key), the computer will compute 2 + 2 and print this answer onto paper:
  548.  4
  549.     Eject the paper manually Although the computer prints that answer onto paper, the paper remains stuck in the printer, until you tell the printer to eject the paper. Ejecting the paper is called ``doing a form feed'', because it feeds a sheet of paper (a form) through the printer.
  550.     To eject the paper manually, press the printer's form-feed button. For example, if your printer's an Epson 5000 (or a similar dot-matrix printer), push the printer's LF/FF button awhile (because that's the form-feed button). If your printer's a Hewlett-Packard Laserjet 2 (or a similar laser printer), press the printer's ON LINE button (so the ON LINE light turns off), then the FORM FEED button, then the ON LINE button again (so the ON LINE light turns back on).     Eject the paper automatically Instead of ejecting paper manually, you can make the computer eject paper AUTOMATICALLY, by putting this line at the bottom of your program:
  551. LPRINT CHR$(12);
  552. That line works for all popular printers.
  553.     For example, this program makes the computer figure out the answer to 2+2, print the answer (4) onto paper, and then eject the paper from the printer:
  554. CLS
  555. LPRINT 2 + 2
  556. LPRINT CHR$(12);
  557.     This program prints a poem on paper and then ejects the paper:
  558. CLS
  559. LPRINT "I see England."
  560. LPRINT "I see France."
  561. LPRINT "I see Batman's"
  562. LPRINT "underpants!"
  563. LPRINT CHR$(12);
  564.     If you want to print several copies of that poem onto paper (so you can hand the copies to several friends), run that program several times: each time, say run (by pressing SHIFT with F5) and return to the blue screen (by pressing F4).
  565.     Dual printing If you say PRINT 2 + 2, the computer prints the answer (4) onto the screen. If you say LPRINT 2 + 2, the computer prints 4 onto paper instead. If you want to print the answer onto the screen and also onto paper, say PRINT and also LPRINT, like this:
  566. Program        What the computer will do
  567. CLS                Clear the screen.
  568. PRINT 2 + 2        Print the answer (4) onto the screen.
  569. LPRINT 2 + 2        Print the answer (4) onto paper.
  570. LPRINT CHR$(12);    Eject the paper from the printer.
  571.     Screen dump Here's another way to print on paper: while you're looking at the computer's answers (on the black screen), press the PRINT SCREEN key (which is on the computer's keyboard, near the top right corner).
  572.     That makes the computer dump onto paper a snapshot of everything that's on the screen. The snapshot on paper is called a screen dump.
  573.     After pressing the PRINT SCREEN key, eject the paper manually.
  574.     If you want to print several copies on paper, press the PRINT SCREEN key several times ___ and eject the paper manually each time.
  575.  
  576.                                                                                                                                                                                                                                 WIDTH 40
  577.     At the top of your program, instead of saying CLS, you can say:
  578. WIDTH 40
  579. Like the CLS command, it makes the computer erase the screen. But it also makes all characters on the black screen be extra wide. It makes those characters be twice as wide as normal, so just 40 of them fit on a line (instead of 80). The characters look dramatically huge!
  580.     Though WIDTH 40 widens the computer's answers on the black screen, it does not widen characters on paper or on the blue screen (where you type your program).     If you tap the Alt key and then the F key, you'll see this file menu:
  581. ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  582. ³ New            ³
  583. ³ Open...        ³
  584. ³ Save           ³
  585. ³ Save As...     ³
  586. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  587. ³ Print...       ³
  588. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  589. ³ Exit           ³
  590. ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  591. Here's how to use it. . . . 
  592.  
  593.                                               Print
  594.     If you choose Print from that menu (by pressing the P key) and then press the ENTER key, the computer will copy the program onto paper.
  595.     For example, if the screen shows this program ___ 
  596. CLS
  597. PRINT 2 + 2
  598. the printer will print this onto paper:
  599. CLS
  600. PRINT 2 + 2
  601.     Then eject the paper manually.
  602.  
  603.                                               Save
  604.     If you want the computer to copy the program onto your hard disk, choose Save from the file menu, by pressing the S key.
  605.     Invent a name If you haven't invented a name for the program yet, the computer will say ``File Name'' and wait for you to invent a short name. Invent any short name you wish. For example, the name can be JOE or SUE or LOVER or POEM4U.
  606.     Pick a name that reminds you of the program's purpose. For example, if the program prints a bill to a customer, call the program ``BILL''; if the program plays chess, call the program ``CHESS''; if it gives a quiz, call it ``QUIZ''; if it tutors a human about the elements of sex, call it ``SEX''; if it tutors a human about advanced sex, call it ``SEX2''.
  607.     The name must be short (up to 8 characters long) and should be simple (consisting of just letters and digits).
  608.     When you finish typing the name, press the ENTER key. Then the computer copies your program to the hard disk.     For example, if you typed the name ``joe'', the computer copies your program to the hard disk and names the program ``JOE.BAS''. (Notice that the computer automatically capitalizes the name and puts .BAS afterwards. The .BAS means ``written in BASic''.)
  609.     Exception: if the name you invented was already used by another program, the computer asks you, ``Overwrite?'' Press the Y key if you want the new program to replace the old program, so the old program disappears. If you do not want the new program to replace the old program, press N instead of Y, then invent a different name for your new program.
  610.     Save often Suppose you're creating a program that's so long it takes you several hours to type. You'll be upset if, after several hours of typing, your town suddenly has a blackout that makes the computer forget what you typed.
  611.     To protect yourself against such a calamity, choose Save from the file menu every fifteen minutes. Then if your town has a blackout, you'll lose just a few minutes of work; the rest of your work will have already been saved on the disk.
  612.     Saving your program every fifteen minutes protects you against blackouts and also again ``computer malfunction'' and any careless errors you might make.
  613.  
  614.                                                                                                                                                                                                            New
  615.     When you've finished inventing and saving a program, here's how to erase the screen, so you can start writing a different program instead: choose New from the file menu (by pressing the N key).
  616.     If you didn't save the program you worked on, the computer asks, ``Save it now?'' If you want to save the program you worked on, press the Y key; if you do not want to save the program you worked on, press the N key instead.
  617.  
  618.                                                                                                                                                                                                           Open
  619.     If you saved a program onto your hard disk, here's how to use it again: choose Open from the file menu (by pressing the letter O).
  620.     The computer shows you an alphabetical list of all BASIC programs on the hard disk. (If the list is too long to fit on the screen, the computer shows you list's beginning.)
  621.     Then say which program you want, by using one of these methods. . . . 
  622. Method 1: type the name of the program you want (such as ``joe''), then press ENTER.
  623.  
  624. Method 2: press the TAB key, then the down-arrow key; then press the down-arrow key a few more times until the program you want is highlighted; then press the ENTER key.
  625.     All lines of that program will appear on the screen.
  626.     (Exception: if a different program has been on the screen and you didn't save it, the computer will ask, ``Save it now?'' If you want to save that program, press the Y key; if you do not want to save that program, press the N key instead.)    
  627.  
  628.                                                                                                                                                                                                        ESCAPE key
  629.     If you change your mind and wish you hadn't requested the file menu, press the ESCAPE key (which says ``Esc'' on it). The file menu will disappear.
  630.  
  631.                                                                                                                                                                                                          Save As
  632.     Here's how to create a program called JOE, then create a variant of it called JOE2.
  633.     First, type the JOE program and save it. Then edit that program, choose Save As from the file menu (by pressing the A key), and type ``JOE2'' (and press ENTER).
  634.  
  635.                                                                                                                                                                                                           Exit
  636.     When you've finished using QBASIC, choose Exit from the file menu, by pressing the X key.
  637.     (If you didn't save the program you worked on, the computer asks, ``Save it now?'' If you want to save the program you worked on, press the Y key; if you do not want to save the program you worked on, press the N key instead.)
  638.     Then the computer will exit from QBASIC, and the screen will say:
  639. C:\>     Congratulations! You've learned how to program!
  640.     C'mon, write some programs! It's easy! Try it. You'll have lots of fun!
  641.     A person who writes a program is called a programmer. Congratulations: you're a programmer!
  642.     Write several programs like the ones I've shown you already. Then you can put on your resumŵ that you have ``a wide variety of programming experience'', and you can talk your way into a programming job!
  643.     The rest of this chapter explains how to become a good programmer.
  644.  
  645.                                                                     Practice
  646.     Programming the computer is like driving a car: the only way to become an expert is to put your hands on that mean machine and try it yourself.
  647.     If you have access to a computer, put this book next to the computer's keyboard. At the end of each paragraph, type the examples and look, look, see the computer run. Invent your own variations: try typing different numbers and strings. Invent your own programs: make the computer print your name or a poem; make it solve problems from your other courses and the rest of your life. The computer's a fantastic toy. Play with it.
  648.     If you're a student, don't wait for your instructor to give lectures and assign homework. Act now. You'll learn more from handling the computer than from the lectures or readings. Experience counts.
  649.     Let me tell you the story of Charlie. . . . 
  650.     At Wesleyan University's computer center, one of the directors was having trouble making the computer print the university's payroll. He asked me for help, but I said I didn't know either. I saw a little kid sitting at one of the keyboards. ``Hey, Charlie,'' I called to him, ``we're having trouble getting the payroll out.''
  651.     Little Charlie came over and typed some stuff on our keyboard. ``The payroll will be out in a minute,'' he said gleefully.
  652.     Charlie was just in seventh grade. He'd never taken a computer course; his school didn't offer one. But by spending the whole summer just ``hanging around'' our computer, he knew it better than we.
  653.     Be like Charlie. Hang around your computer. Communicate with it every day. At first, that will be even harder than talking with a cat or a tree, because the computer belongs to a different species, a different kingdom; but keep trying. Get to know it as well as you know your best friend.
  654.     If you're taking a French course, you might find French difficult; and if you're taking a computer course, you might find computers difficult also. But even a stupid three-year-old French kid can speak French, and even kindergarten kids can program the computer. They have just one advantage over you: practice!
  655.  
  656.                                                                      Be bold
  657.     In science fiction, computers blow up; in real life, they never do. No matter what keys you press, no matter what commands you type, you won't hurt the computer. The computer is invincible! So go ahead and experiment. If it doesn't like what you type, it will gripe at you, but so what?                                                                                                                                                                                                                                 Troubles
  658.     When you try using the computer, you'll have trouble ___ because you're making a mistake, or the computer is broken, or the computer is weird and works differently from the majority computers discussed in this book. (Each computer has its own ``personality'', its own quirks.)
  659.     Whenever you have trouble, laugh about it, and say, ``Oh, boy! Here we go again!'' (If you're Jewish, you can say all that more briefly, in one word: ``Oy!'') Then get some help.
  660.  
  661.                                                                                                                                                                                                                                 Get help
  662.     For help with your computer, read this book! For further help, read the beginner's manual that came with your computer, or ask the genie who gave you the computer (your salesperson or parent or boss or teacher or friend).
  663.     If you're sitting near computers in your office, school, or home, and other people are nearby, ask them for help. They'll gladly answer your questions because they like to show off and because the way they got to know the answers was by asking.
  664.     Computer folks like to explain computers, just as priests like to explain religion. Remember: you're joining a cult! Even if you don't truly believe in ``the power and glory of computers'', at least you'll have a few moments of weird fun. So play along with the weird computer people, boost their egos, and they'll help you get through your initiation rite. Above all, assert yourself, and ask questions. ``Shy guys finish last.''
  665.     When dealing with the computer and the people who surround it, be friendly but also assertive. To make sure you get your money's worth from a computer course, ask your teacher, classmates, lab assistants, and other programmers questions, questions, questions! If you're using a computer that you own, get help from the person who gave it to you.
  666.     Your town probably has a computer club. (To find out, ask the local schools and computer stores.) Join the club, and tell the members you'd like help with your computer. Probably some computer hobbyist will help you.
  667.     And remember ___  you can call me anytime at 617-666-2666, and I'll help you, free!     You can control how your computer goes and stops.
  668.  
  669.                                           Instant open
  670.     Suppose you've saved a QBASIC program called JOE.
  671.     To use JOE, you could turn on the computer, then say ___ 
  672. C:\>qbasic
  673. then choose Open from the file menu, then type ``joe'' (and press ENTER).
  674.     Here's a faster way! Turn on the computer, then say:
  675. C:\>qbasic joe
  676. That makes the computer use QBASIC and instantly open JOE.
  677.     Qbasic /run Try saying this:
  678. C:\>qbasic /run joe
  679. That makes the computer use QBASIC, instantly open JOE, and automatically run JOE. Moroever, if JOE's bottom line says ``SYSTEM'', like this ___ 
  680. CLS
  681. PRINT "I love you"
  682. SYSTEM
  683. the computer will automatically exit from QBASIC when JOE finishes running.
  684.     Batch files You can create a DOS batch file and make one of the lines in it say:
  685. qbasic /run joe
  686. Then whenever you run that batch file, the computer will automatically run JOE.
  687.     For example, if your AUTOEXEC.BAT file includes a line saying ``qbasic /run joe'', the computer will automatically run JOE every time you turn on the computer.                                                                                                                                                                                                           SLEEP
  688.     If you say SLEEP, the computer will take a nap:
  689. CLS
  690. PRINT "I'm going to take a nap."
  691. SLEEP
  692. PRINT "Thanks for waking me up."
  693. The second line makes the computer announce:
  694. I'm going to take a nap.
  695. The next line says SLEEP, which makes the computer take a nap. The computer will continue sleeping until you wake it up by pressing a key on the keyboard. (Press any key, such as ENTER.) Then the computer, woken up, will finish running the rest of the program, whose bottom line makes it say:
  696. Thanks for waking me up.
  697.     Valentine's Day This program lets the computer gripe about how humans treated it on Valentine's Day:
  698. CLS
  699. PRINT "Valentine's Day, you didn't bring me flowers!"
  700. PRINT "I won't speak until you gimme roses!"
  701. PRINT "Bring them, then touch one of my keys."
  702. SLEEP
  703. PRINT "It's great to wake up and smell the roses!"
  704.     Lines 2-4 make the computer say:
  705. Valentine's Day, you didn't bring me flowers!
  706. I won't speak until you gimme roses!
  707. Bring them, then touch one of my keys.
  708. The next line (SLEEP) makes the upset computer go to sleep and refuse to talk to humans, until a human presses a key. When a human finally presses a key, the computer wakes up and says:
  709. It's great to wake up and smell the roses!
  710.     Timed pause Instead of letting the computer sleep a long time, you can set an alarm clock so the computer will be forced to wake up soon. For example, if you say SLEEP 6 (instead of just SLEEP), the computer will sleep for just 6 seconds.
  711.     That's how to make the computer pause for 6 seconds. Give that 6-second pause before you reveal the punch line of a joke:
  712. CLS
  713. PRINT "Human, your intelligence is amazing!  You must be an M.D.";
  714. SLEEP 6
  715. PRINT "--Mentally Deficient!"
  716. That program makes the computer print the joke's setup (``Human, your intelligence is amazing! You must be an M.D.''), then pause for 6 seconds, then reveal the joke's punch line, so the screen finally shows:
  717. Human, your intelligence is amazing!  You must be an M.D.--Mentally Deficient!
  718.     SLEEP 6 makes the computer sleep until it gets woken up by either the alarm clock (after 6 seconds) or the human (by pressing a key). If you want the computer to pause for 10 seconds instead of 6, say SLEEP 10 instead of SLEEP 6. The number after the word SLEEP can be 6 or 10 or any other positive whole number, but not a decimal.
  719.     This program makes the computer brag, then confess:
  720. CLS
  721. PRINT "We computers are smart for three reasons."
  722. PRINT "The first is our VERY GOOD MEMORY."
  723. PRINT "The other two reasons . . . ";
  724. SLEEP 10
  725. PRINT "I forgot."
  726. The computer begins by bragging: 
  727. We computers are smart for three reasons.
  728. The first is our VERY GOOD MEMORY.
  729. The other two reasons . . . 
  730. But then the computer pauses for 10 seconds and finally admits:
  731. I forgot.
  732.     This program makes the computer change its feelings, in surprising ways:
  733. CLS
  734. PRINT "I'm up";
  735. SLEEP 3
  736. PRINT "set!  I want to pee";
  737. SLEEP 4
  738. PRINT "k at you";
  739. SLEEP 5
  740. PRINT "r ma";
  741. SLEEP 6
  742. PRINT "nual";
  743. SLEEP 7
  744. PRINT "dexterity.  Touch me!"
  745. The computer will print ___ 
  746. I'm up
  747. then pause 3 seconds and change it to ___ 
  748. I'm upset!  I want to pee
  749. then pause 4 seconds and change it to ___ 
  750. I'm upset!  I want to peek at you
  751. then pause 5 seconds and change it to ___ 
  752. I'm upset!  I want to peek at your ma
  753. then pause 6 seconds and change it to ___ 
  754. I'm upset!  I want to peek at your manual
  755. then pause 7 seconds and change it to ___ 
  756. I'm upset!  I want to peek at your manual dexterity.  Touch me!
  757.     Experiment: invent your own jokes, and make the computer pause before printing the punch lines.
  758.     Speed-reading test This program tests how fast you can read:
  759. CLS
  760. PRINT "If you can read this, you read quickly."
  761. SLEEP 1
  762. CLS
  763.     When you run that program, the computer makes the screen display this message:
  764. If you can read this, you read quickly.
  765. Then the computer pauses for 1 second (because of the SLEEP 1), then erases the screen (CLS). So the message appears on the screen for just 1 second before being erased!
  766.     If you manage to read that entire message in just 1 second, you're indeed a fast reader!
  767.     But don't stop at that first success! For the ultimate challenge, try running this program:
  768. CLS
  769. PRINT "Mumbling morons make my mom miss murder mysteries Monday morning."
  770. SLEEP 2
  771. CLS
  772. That makes the computer display this tongue-twister ___ 
  773. Mumbling morons make my mom miss murder mysteries Monday morning.
  774. then pause for 2 seconds, then erase the screen. During the 2 seconds while that tongue-twister appears on the screen, can you recite the entire twister out loud? Try it! If you don't recite it properly, you'll sound like a mumbling moron yourself!                                                                                                                                                                                                                                                       DO . . . LOOP
  775.     This program makes the computer print the word ``love'' once:
  776. CLS
  777. PRINT "love"
  778.     This fancier program makes the computer print the word ``love'' three times:
  779. CLS
  780. PRINT "love"
  781. PRINT "love"
  782. PRINT "love"
  783. When you run that program, the computer will print:
  784. love
  785. love
  786. love
  787.     Let's make the computer print the word ``love'' many times. To do that, we must make the computer do this line many times:
  788. PRINT "love"
  789. To make the computer do the line many times, say ``DO'' above the line and say ``LOOP'' below it, so the program looks like this:
  790. CLS
  791. DO
  792.         PRINT "love"
  793. LOOP
  794. As you can see, put the line being repeated (PRINT ``love'') between the words DO and LOOP and indent it. (To indent, press the SPACE bar repeatedly or ___ better yet ___ press the TAB key once. To remove an indentation, put yourself just after the indentation and then press the BACKSPACE key.) When you run that program, the computer will do PRINT ``love'' many times and print:
  795. love
  796. love
  797. love
  798. love
  799. love
  800. love
  801. love
  802. love
  803. love
  804. etc.
  805. The computer will print ``love'' on every line of your screen.
  806.     But even when the screen is full of ``love'', the computer won't stop: the computer will try to print even more loves onto your screen! The computer will lose control of itself and try to devote its entire life to making love! The computer's mind will spin round and round, always circling back to the thought of making love again!     Since the computer's thinking keeps circling back to the same thought, the computer is said to be in a loop. In that program, the DO means ``do what's underneath and indented''; the LOOP means ``loop back and do it again''. The lines that say DO and LOOP ___ and the lines between them ___ form a loop, which is called a DO loop.
  807.     To stop the computer's lovemaking madness, you must give the computer a ``jolt'' that will put it out of its misery and get it out of the loop. To jolt the computer out of the program, abort the program.
  808.     Here's how to abort the program: while holding down the Ctrl key, tap the PAUSE/BREAK key, which is the last key in the top row. (If your keyboard is modern, that key says PAUSE and BREAK on it. If your keyboard is old-fashioned, that key says SCROLL LOCK and BREAK on it.) That makes the computer stop running your program; it will break out of your program; it will abort your program and show you the blue screen so you can edit the program.
  809.     In that program, since the computer tries to go round and round the loop forever, the loop is called infinite. The only way to stop an infinite loop is to abort it.
  810.     Semicolon For more lovely fun, put a semicolon after ``love'', so the program looks like this:
  811. CLS
  812. DO
  813.         PRINT "love";
  814. LOOP
  815. The semicolon makes the computer print ``love'' next to ``love'', so the screen looks like this:
  816. lovelovelovelovelovelovelovelovelovelovelovelovelovelovelovelovelovelovelovelove
  817. lovelovelovelovelovelovelovelovelovelovelovelovelovelovelovelovelovelovelovelove
  818. lovelovelovelovelovelovelovelovelovelovelovelovelovelovelovelovelovelovelovelove
  819. etc.
  820.     If you put a space after love, like this ___ 
  821. CLS
  822. DO
  823.         PRINT "love ";
  824. LOOP
  825. the computer will put a space after each love:
  826. love love love love love love love love love love love love love love love love
  827. love love love love love love love love love love love love love love love love
  828. love love love love love love love love love love love love love love love love
  829. etc.
  830.     Bigger DO loop Run this program:
  831. CLS
  832. DO
  833.         PRINT "dog";
  834.         PRINT "cat";
  835. LOOP
  836.     Lines 3 & 4 (which say PRINT ``dog'' and PRINT ``cat'') make the computer print ``dog'' and then print ``cat'' next to it. Since those lines are between the words DO and LOOP, the computer does them repeatedly ___ PRINT ``dog'', then PRINT ``cat'', then PRINT ``dog'' again, then PRINT ``cat'' again ___ so the screen looks like this:
  837. dogcatdogcatdogcatdogcatdogcatdogcatdogcatdogcatdogcatdogcatdogcatdogcatdogcat
  838. dogcatdogcatdogcatdogcatdogcatdogcatdogcatdogcatdogcatdogcatdogcatdogcatdogcat
  839. dogcatdogcatdogcatdogcatdogcatdogcatdogcatdogcatdogcatdogcatdogcatdogcatdogcat
  840. etc.
  841.     The computer will keep printing ``dog'' and ``cat'' until you abort the program by doing this: while holding down the Ctrl key, tap the PAUSE/BREAK key.     Blinking Let's make the screen say ``Stop pollution!'' and make that message blink.
  842.     To do that, flash ``Stop pollution!'' onto the screen for 2 seconds, then turn that message off for 1 second (so the screen is blank), then flash that message on again. Here's the program:
  843. WIDTH 40
  844. DO
  845.         PRINT "Stop pollution!"
  846.         SLEEP 2
  847.         CLS
  848.         SLEEP 1
  849. LOOP
  850.     The top line (WIDTH 40) makes sure all characters appear dramatically huge.
  851.     Lines 3 & 4 (which say PRINT ``Stop pollution!'' and SLEEP 2) flash the message ``Stop pollution!'' onto the screen and keep it on the screen for 2 seconds. The next pair of lines (CLS and SLEEP 1) make the screen become blank for 1 second. Since those lines are all between the words DO and LOOP, the computer does them repeatedly ___ flash message then blank, flash message then blank, flash message then blank ___ so your screen becomes a continually flashing sign.
  852.     The screen will keep flashing until you abort the program by doing this: while holding down the Ctrl key, tap the PAUSE/BREAK key.
  853.     Instead of saying ``Stop pollution!'', edit that program so it flashes your favorite phrase instead, such as ``Save the whales!'' or ``Marry me!'' or ``Keepa youse hands offa my computer!'' or ``Jesus saves ___ America spends!'' or ``In God we trust ___ all others pay cash'' or ``Please wait ___ Dr. Doom will be with you shortly'' or ``Let's rock!'' or whatever else turns you on. Make the computer say whatever you feel emotional about. Like a dog, the computer imitates its master's personality. If your computer acts ``cold and heartless'', it's because you are!
  854.     In the program, you typed just a few lines; but since the bottom line said LOOP, the computer does an infinite loop. By saying LOOP, you can make the computer do an infinite amount of work. Moral: the computer can turn a finite amount of human energy into an infinite amount of good. Putting it another way: the computer can multiply your abilities by infinity.     Computerized copier Suppose you want to send this poem to all your friends:
  855. I'm having trouble
  856. with my nose.
  857. The only thing it does is:
  858. Blows!
  859.     Type this program:
  860. CLS
  861. DO
  862.         LPRINT "I'm having trouble"
  863.         LPRINT "With my nose."
  864.         LPRINT "The only thing it does is:"
  865.         LPRINT "Blows!"
  866.         LPRINT CHR$(12);
  867. LOOP
  868.     Since it says LPRINT instead of PRINT, it prints each copy on paper instead of on the screen. Since the LPRINT lines are in a DO loop, the computer prints the poem again and again, many times, until you abort the program ___ or the printer runs out of paper.
  869.     Each time the computer prints a copy of the poem, the ``LPRINT CHR$(12);'' makes the computer eject a sheet of paper, so each copy of the poem is on a separate page.
  870.     Before running that program, put into the printer just as many sheets of paper as you want copies. If you put in too many sheets of paper, you'll get more copies than you want, and you'll waste paper.                                                                                                                                                                                                                               Line numbers
  871.     You can number the lines in your program. For example, instead of typing ___ 
  872. CLS
  873. DO
  874.         PRINT "love"
  875. LOOP
  876. you can type:
  877. 1 CLS
  878. 2 DO
  879. 3       PRINT "love"
  880. 4 LOOP
  881.     Then when you're discussing your program with another programmer, you can talk about ``line 3'' instead of having to talk about ``the line in the middle of the DO loop''.
  882.     Selective numbering You can number just the lines you're planning to discuss.
  883.     For example, if you're planning to discuss just lines 2 and 4, you can number just those lines:
  884. CLS
  885. 2 DO
  886.         PRINT "love"
  887. 4 LOOP
  888. Or if you prefer, number them like this:
  889. CLS
  890. 1 DO
  891.         PRINT "love"
  892. 2 LOOP
  893.     Decimal numbers Here's a simple program:
  894. 1 CLS
  895. 2 PRINT "Life's a blast!"
  896. Suppose you want to edit it and insert an extra numbered line between 1 and 2. QBASIC lets you give the extra line a decimal number, such as 1.5:
  897. 1 CLS
  898. 1.5 PRINT "I hope..."
  899. 2 PRINT "Life's a blast!"
  900.     Number by tens Instead of making line numbers be 1, 2, 3, etc., make the line numbers be 10, 20, 30, etc., like this:
  901. 10 CLS
  902. 20 PRINT "Life's a blast!"
  903. Then you can insert an extra line without using decimals:
  904. 10 CLS
  905. 15 PRINT "I hope..."
  906. 20 PRINT "Life's a blast!"
  907.  
  908.                                                                                                                                                                                                                                   GOTO
  909.     This program makes the computer print the words ``dog'' and ``cat'' repeatedly:
  910. CLS
  911. DO
  912.         PRINT "dog";
  913.         PRINT "cat";
  914. LOOP
  915. It makes the computer print: dogcatdogcatdogcatdogcatdogcatdogcatdogcatdogcatdogcatdogcatdogcatdogcatdogcat
  916. dogcatdogcatdogcatdogcatdogcatdogcatdogcatdogcatdogcatdogcatdogcatdogcatdogcat
  917. dogcatdogcatdogcatdogcatdogcatdogcatdogcatdogcatdogcatdogcatdogcatdogcatdogcat
  918. etc.
  919.     This program does the same thing:
  920. CLS
  921. 10 PRINT "dog";
  922. PRINT "cat";
  923. GOTO 10
  924. The second line (which is numbered 10) makes the computer print ``dog''.  The next line makes the computer print ``cat''. The bottom line makes the computer GO back TO line 10, so the computer will print ``dog'' again, then ``cat again'', then GO back TO line 10 again, then print ``dog'' again, then ``cat'' again, etc. The computer will print ``dog'' and ``cat'' repeatedly, until you abort the program by pressing SHIFT with PAUSE/BREAK.
  925.     This program does the same thing:
  926. CLS
  927. joe: PRINT "dog";
  928. PRINT "cat";
  929. GOTO joe
  930. The second line (named ``joe'') makes the computer print ``dog''. The next line makes the computer print ``cat''. The bottom line makes the computer GO back TO the line named ``joe''. In that program, ``joe'' is called the second line's label.
  931.     One word In QBASIC, ``GOTO'' is one word. You're supposed to type ``GOTO'', not ``GO TO''. When you press the ENTER key at the end of the line, the computer will automatically turn any ``GO TO'' into ``GOTO''.
  932.     Skip ahead Did you ever dream about having a picnic in the woods? This program expresses that dream:
  933. CLS
  934. PRINT "Let's munch"
  935. PRINT "sandwiches under"
  936. PRINT "the trees!"
  937. It makes the computer print:
  938. Let's munch
  939. sandwiches under
  940. the trees!
  941.     Let's turn that dream into a nightmare where we all become giant termites. To do that, insert the shaded items:
  942. CLS
  943. PRINT "Let's munch"
  944. GOTO 10
  945. PRINT "sandwiches under"
  946. 10 PRINT "the trees!"
  947. The computer begins by printing ``Let's munch''. Then the computer does GOTO 10, which makes the computer GO skip down TO line 10, which prints ``the trees!'' So the program makes the computer print just this:
  948. Let's munch
  949. the trees!
  950.     Is GOTO too powerful? The word GOTO gives you great power: if you say GO back TO line 10, the computer will create a loop (as if you'd said DO...LOOP); if you say GO skip down TO line 10, the computer will skip over several lines of your program.
  951.     Since the word GOTO is so powerful, programmers fear it! Programmers know that the slightest error in using that powerful word will make the programs act very bizarre! Programmers feel more comfortable using milder words instead (such as DO...LOOP), which are safer and rarely get botched up. Since the word GOTO is scary, many computer teachers prohibit students from using it, and many companies fire programmers who say GOTO instead of DO...LOOP.
  952.     But saying GOTO is fine when you've learned how to control the power! Though I'll usually say DO...LOOP instead of GOTO, I'll say GOTO in certain situations where saying DO...LOOP would be awkward.
  953.  
  954.                                                                                     Life as an infinite loop
  955.     A program that makes the computer do the same thing again and again forever is an infinite loop.     Some humans act just like computers. Those humans do the same thing again and again. Every morning they GOTO work, and every evening they GOTO home. GOTO work, GOTO home, GOTO work, GOTO home, . . . Their lives are sheer drudgery. They're caught in an infinite loop.
  956.     Go to your bathroom, get your bottle of shampoo, and look at the instructions on the back. A typical bottle has three instructions:
  957. Lather.
  958. Rinse.
  959. Repeat.
  960. Those instructions say to lather, then rinse, then repeat ___ which means to lather again, then rinse again, then repeat again ___ which means to lather again, then rinse again, then repeat again. . . . If you follow those instructions, you'll never finish washing your hair! The instructions are an infinite loop! The instructions are a program: they program you to use lots of shampoo! That's how infinite loops help sell shampoo.
  961.  
  962.                                                                                                                                                                                                                                                            END
  963.     To make the computer skip the bottom part of your program, say END:
  964. CLS
  965. PRINT "She smells"
  966. END
  967. PRINT "of perfume"
  968.     When you run that program (by pressing SHIFT with F5), the computer will print ``She smells'' and then end, without printing ``of perfume''.
  969.     Suppose you write a program that prints a long message, and you want to run the program several times (so several of your friends get the message). If one of your friends would be offended by the end of your message, send that friend an abridged message! Here's how: put END above the part of the message that you want the computer to omit ___ or skip past that part by saying GOTO.
  970.  
  971.                                                                                                                                                                                                                                                   Multi-statement line
  972.     In your program, a line can contain several statements separated by colons, like this:
  973. CLS: PRINT "I dream": PRINT "of you"
  974.     When you run that program, the computer will CLear the Screen, then PRINT ``I dream'', then PRINT ``of you''. Altogether, the computer will print:
  975. I dream
  976. of you
  977.     If you want to number the line, put the number at the left margin, like this:
  978. 10 CLS: PRINT "I dream": PRINT "of you"
  979.