TOC Letter writing with GW-Basic

The Letters

Letter writing with GW-Basic is so easy that i feel like a real dope for not understanding its simplicity and ease of use many years before - like 20 years before. You can write or print a letter using as little as 24 bytes of code plus your letter data. Now that is simple. really, really, simple. Anyhow here it is...
GW-Basic letters can be created using the DATA-READ statements. Now don't panic if you don't know what the data-read stuff is, you don't even have to know what it is. Later on, lots of later on, it might come to you. For now, don't give it a second thought. Just copy the code and.. that's about it.
First, let's create a empty form with which we can write letters. Fire up GW-Basic, type cls to clear the screen, then type <key off> (without the angle brackets) and then type this in GW-Basic itself:
LINE zero to line 9 0 data " and press <enter> remember that zero (0) is a zero and not an oh (O). And don't forget the space between the number zero (0) and the word DATA and the space between the "a" and the single quote ("). show you why in a minute. That's it. That's all. now go up to the zero and overtype it with a one (1), press <enter> then go back and do a two (2), then press <enter> then go back and do a three (3) then press <enter> then go back and do a four (4) then press <enter> and so on and so forth (leave out the parenthesis of course) until you reach 9. Now type LIST and press enter. You should get a listing that looks something like this: 0 DATA " 1 DATA " 2 DATA " 3 DATA " 4 DATA " 5 DATA " 6 DATA " 7 DATA " 8 DATA " 9 DATA " If you are missing any of the line numbers, you forgot to press <enter> after typing in the number. Basic uses line numbers and that is what you were typing in. To fix any problem just overtype any of the numbered data statments with the missing number, then press enter and then relist. Eventually, you will get it right and the next time it will be second nature.
LINE 10-19 Now, since there are about 54 to 60 lines in a letter, depending on the top and bottom margins, lets go back and type: 10 DATA" and then press the enter key. Notice now that the quote is up against the DATA statement and does not have the space between it. Then go to the zero in the ten (10) number and type a "one" (1) to make it eleven (11) and then press enter. back to the one and type a two to make it a twelve (12) back to the two and type a three to make it a thirteen (13) and so on til 19 Then type <LIST> and press the enter key. The listed program should LIST out as: 0 DATA " 1 DATA " 2 DATA " 3 DATA " 4 DATA " 5 DATA " 6 DATA " 7 DATA " 8 DATA " 9 DATA " 10 DATA" 11 DATA" 12 DATA" 13 DATA" 14 DATA" 15 DATA" 16 DATA" 17 DATA" 18 DATA" 19 DATA" Notice how the single quote "lines up"
LINE 20-59 Now go back and everywhere from 10 to 19, type a two where the "one" is in first place and press enter <again>. Repeat the process using the numbers 3,4,5 to turn them into the thirties, forties, and fifties. Okay, now we are up to 60 lines of data lines awaiting our letter. Don't forget our letter lines start at zero so line 59 is really line 60 of our letter. We can fix that later if it drives you buggy.
LINE 60 For line 61 of our BASIC program, type 60, and then a space and then an apostrophe about 5 or so blank spaces, then the word SAVE, then the name of the letter file with a dot (.) something extension which would be either .BAS, .FRM .TXT .DOC .LET or anything really, surrounded by quotes followed by a comma (,) then finally, the letter a to save the file as an ASCII file. case doesn't make any difference. Line 60 should look like this: 60 ' SAVE"letter.frm",a Use this first empty basic program saved as a form only from which you can call and use over and over again. After you have used the .frm and you have finished writing your letter, you can save it to a different name each time you write a different letter. For example: 62 ' save"letr2mom.bas",a or 62 ' save"mothers.let",a Putting a line 62 in at this point allows you to save your letter to a different name easily even if you are not quite finished with it. How do you do that? Just move the cursor over the 6 in 60 or line 62 and press delete until the REM tag (apostrophe) disappears, then press enter. voila! your letter is saved. type LIST (lines) to see your letter and to continue with your writing or editing the letter if you want. more on this later. Don't forget to press the <enter> key to get the new lines to become part of the GW-Basic program.
LINE 61 Now for line 61 we do some heavy GW-Basic coding to print our letter or show it on the screen. 61 FOR I=0 TO 59:READ S$: PRINT S$:NEXT I Now don't forget to press <enter> to get line 61 into the basic program listing. That's it, a whole half line of code to write any letter, memo, rfq or whatever in GW-Basic. It just doesn't get any easier or simpler than that.
Now to write the letter Place the cursor at line 0 and press the TAB key. Notice the cursor moves past the DATA " portion of the line and is now inside the data area. Start typing your letter, If you make a mistake, press the back space key and make your correction before you get to the end of the line. At the end of the line just press the enter key and then the tab key again to get past the next 'N DATA " portion of the next line in the datafile to write the second line of your letter. Continue typing your letter all the way down to line 59 (or 60) if you started you numbering at line 1. Optionally, you can either save the letter file or not save the letterfile. By just typing "run" from any cleared line of your letter, GW-BASIC will start the for-next loop read all the data, and then print the letter either to the screen or to the printer, depending on how you have coded your program.
Advanced printing directives To send your letter to your printer, just add an L in front of the word print so that it looks like: 61 FOR I=0 TO 59: READ S$: LPRINT S$: NEXT Depending on your printer, you may want to place three to six PRINT or LPRINT at the front of the for-next loop to space the letter horizontally on the page. 61 LPRINT: LPRINT: LPRINT: FOR I=0 TO 59: READ S$: LPRINT S$: NEXT Also stick in a TAB(9) statement in the LPRINT statement to proportion it horizonally on the page. 61 LPRINT: LPRINT: LPRINT 62 FOR I=0 TO 59: READ S$: LPRINT TAB(9)S$: NEXT You may have to play around with the numbers on this stuff until you get something that appeals to you visually, but the offered numbers are a good starting place. That's it.
Except for one more thing... Well, if you are ready for a more "expert" way of creating your basic letter form you can try this. GW-BASIC has a LOT of tricks up its sleeve. For our current purposes we can use two of the features. Auto This command starts automatic line numbering. So if you type in Auto while in GW-BASIC it will put a 10 for a line number and increment each new line number automatically by ten. neat. Plus, you can change the auto line numbering by supplying your own parameters. For example by typing: AUTO 5,2 starts line numbering at 5 and increments by 2 AUTO 1,1 starts line numbering at 1 and increments by 1 if a program is already loaded you can still use the AUTO by starting line numbering at a higher than the last number of the existing program. for example the loaded program ends at line 3400 so you type AUTO 3500, 10 and you are off and running. So now we got the AUTO command down sortof. But read the documentation for a fuller discussion, PLEASE. You can cancel the automatic line numbering of the AUTO command feature by pressing <Control> C
Let the function key do the typing for you! Next we redefine a function key to type a string (a series of letters) when pressed, up to 15 characters are permitted if memory serves me. (it usually doesn't) We do that by typing in immediate mode: Key 4,"DATA" + chr$(34) So now whenever we press the F4 key the word DATA" magically appears for that program. Don't forget the quote sign. Okay so now type AUTO then press the F4 key. You should see, if you did everything correct this code on the screen. 10 DATA" Next press the enter key and the number 20 should appear. press the F4 key again. voila! the word DATA appears after the line number. Now keep pressing the ENTER key and the F4 key alternately in a rat-tat-tat volley of keystrokes. The line numbers with the data" statements should appear as if by magic. And as long as you keep up the rat-tat-tatting, the basic letter form should keep growing in length to as long as you want your letter to be. You only have to do this once or occasionally in your basic career so like me, you will probably forget how to, by the time you need to. When you are done rat-tat-tatting, save whatever length form you have created that you wanted as LETTER.FRM or whatever other file name suits you and use the basic form(s) for your future letter writing. You can go one page, two pages, three pages. and so on... That's it.
Oops! Except for one or two more things, "tips!" actually. #1) you have 10 function keys so at 15 characters each you can program each function key sequentially to do part of a string, giving you a 150 character limit if need be. i have never needed it to be, but who knows? #2) You can program the function keys to put in the box drawing characters for the function keyword wrap in your mnu-nnnn.bas programs. i think. i haven't really tried this yet so maybe i should shut up... back in a flash.. Yup! it works okay. But don't forget to enclose the string of high order ascii characters in quotes to print to screen.
Well... here is yet another tiny basic program involving letter writing that you might find usable. There is nothing preventing you from adding an ounce of other gw-basic code as opposed to a ton of .dll stuff. Frankly, after writing it, i never did use it much. included some error trapping on the printer. it's okay, but... who needs it? Just turn on the printer. what are we? professional coders? 0 VIEW PRINT:CLS 1 DATA "Dear Uncle and Aunt, 11:00am Wednesday May 6, 1998 2 DATA " 3 DATA " 4 DATA " 5 DATA " 6 DATA " 7 DATA " 8 DATA " Your letter goes in here 9 DATA " 10 DATA" 11 DATA" 12 DATA" 13 DATA" 14 DATA" 15 DATA" 16 DATA" 17 DATA" 18 DATA" 19 DATA" 20 DATA" 21 DATA" 22 DATA" 23 DATA" 24 DATA" 25 DATA" 26 DATA" 27 DATA" 28 DATA" 29 DATA" 30 DATA" 31 DATA" 32 DATA" 33 DATA" 34 DATA" 35 DATA" 36 DATA" 37 DATA" 38 DATA" 39 DATA" 40 DATA" 41 DATA" 42 DATA" 43 DATA" 44 DATA" 45 DATA" 46 DATA" 47 DATA" 48 DATA" 49 DATA" 50 DATA" 51 DATA" 52 DATA" 53 DATA" 54 DATA" 55 DATA" 56 DATA" 57 DATA" 58 DATA" 59 DATA" 60 DATA" 61 DATA"END OF DATA" 62 READ S$ 63 IF S$="END OF DATA" THEN 69 64 PRINT TAB(5)S$ 65 FOR DL=1 TO 100!: NEXT DL 66 GOTO 62 67 ' error routine 68 '-----------------------------------------Error routine start here 69 'RunThisSubroutineIfAnErrorOccurs: 70 ON ERROR GOTO 84 71 PRINT:PRINT:PRINT TAB(30); 72 INPUT "Ready to print? (y/n)";YN$ 73 IF YN$="y" OR YN$="Y" THEN 76 74 PRINT:PRINT:PRINT TAB(30)"Returned to Interpreter..." 75 PRINT:PRINT:PRINT:END 76 RESTORE 77 READ S$ 78 IF S$="END OF DATA" THEN 81 79 LPRINT TAB(5)S$ 80 GOTO 77 81 PRINT:PRINT:PRINT TAB(30)"Finished spooling to printer..." 82 END 83 RUN"mnu-main 84 ' ------------------------------------------------------------------ 85 ' error handling routines 86 ' ------------------------------------------------------------------ 87 PRINT:PRINT 88 PRINT TAB(15)"Printer not online, make sure printer is turned on" 89 PRINT TAB(15)"and that you have sufficient paper loaded..." 90 PRINT:PRINT:PRINT "Error line is: ";ERL, "the error code is: ";ERR 91 GOTO 70 92 ' SAVE "uncle.BAS",A
Back to GW-BASIC Table of Contents
Back to Frankenbook's Table of Contents.
Hosted by