A QL Address File

Author(s): Robert Hartung
Publication: Update Magazine
Pub Details: Update October 1988
Date: October 1988
Pages: 44-48

Some like myself who are new Kids on the block with the QL may be looking for info on getting started in QL SuperBasic programming. The QL User’s Guide (QLUG) is something less than a masterpiece of clarity, and most current publications seem to have moved on to more advanced topics, so, from the perspective of a rank beginner, here are a few “QLues” I have stumbled onto so far. Assuming that not everyone has installed Toolkit II (TKT) or Trump Card, I will use only the syntax accepted by the unexpanded QL unless otherwise noted. Direct command entries will be indicated by <command> with a slash / between those keys to be pressed at the same time.

Since the best way of learning is usually by doing (there are exceptions such as learning what Kinds of wild mushrooms are safe to eat!) I will give the listing for a SuperBasic program, then explain some of the whys and wherefores of it. A reader requested a mail list program, which seems a practical way of illustrating some points. Of course the ARCHIVE database SW bundled with the QL may be adapted for this but all its bells and whistles and whirring microdrives sometimes seem overkill for a simple mailing file and printout.

To make this into something for everyone, I will also try to use syntax that can most easily be translated by TS2068 (and Beta Basic) users, rather than exclusively-QL structures and commands that might be more elegant but less familiar. Purists who are bothered by my use of subroutines instead of structured procedures may easily replace the REM labels with DEFine PROCedure name, the RETurns with END DEFine, and the GO SUBs with the respective procedure names. I ran into an anomaly, however, on the SORT routine when defined as a procedure in that it re-orders a file perfectly the first time but then seems to lose track of some file items on subsequent calls. I’ll leave that as a challenge for a sharp T/S UPDATE reader to figure out!

The minimum essentials of a mailing list are to provide the means of entering, storing, retrieving, and printing out the files. It is also useful to have the means of re-ordering them alphabetically, usually by last names, selecting particular ones for display or printout, adding to the file, and editing or deleting. This program will do all these, albeit more slowly than a whiz-bang machine code or compiled one. To economize on page space a 56-column listing format was used instead of the 40-column MODE 8 or the 64-column MODE 4. Now with all these disclaimers stated, let’s get on with it.

For less pain and strain in entering the listing, <AUTO> supplies line numbers starting at 100 in increments of 10 or <AUTO n> will start at line n in steps of 10. Use <CTRL/SPACE> to break out of AUTO. During entries of a new listing or when editing an old one, <AUTO 10> or in the same increments as the listing will automatically bring each line into edit mode and <ENTER> will scroll to the next. If <EDIT n> is used to bring down a specific line, then the up or down cursor Keys may be used to scroll other lines into the edit window as long as ENTER has not yet been Keyed. Of course TKT users have the many conveniences of full-screen editing but for those who don’t have TKT the QLUG doesn’t go into much detail on how to use these normal EDIT functions to make life a bit easier.

I would suggest starting by entering line 1540 DEFine PROCedure sv: DELETE MDV1_addrfile: SAVE MDV1_addrfile: END DEFine sv. If you do not have the TKT FREE_MEM command you might also want to add line 1550 DEFine PROCedure freemem: PRINT PEEK_L(163856)-PEEK_L(163852)-1024: END DEFine freemem. Make the first save of this with SAVE MDV1_addrfile, or change all the addrfile names to BOOT if you want it to auto-load. Now whenever you want to make a save during entry of the listing all you need to do is Key <sv>. Enter <freemem> to show free memory remaining. Procedure and function definitions like these may be located anywhere and are transparent until called, i.e. processing passes right over them as it does for a DATA line.

Use RUN to initiate and Key “9” from the menu to save the listing to mdv1. To set up an all-new file, Key “0” and “y” at the ERASE prompt. 820 allows entry of 1, 2, 3, 4, or 5 for auto-entry of the respective titles (no space between number and first name). If 9 is the first character entered here then any other title or name may be Keyed in letter-by-letter following the 9. $STOP will close the file and GO SUB to the sort and re-order routine 20, otherwise inputs continue for last name, address, P.O., state & ZIP, and ID or phone no.

The state and ZIP entry may be skipped with just ENTER (N/L) if the P.O. entry was made with a number. 860 & 890-910 may be expanded to include more auto-entries of P.O., state, and ZIPs for frequently-occurring ones. To avoid confusion, use line-increments of 1 for this and wait until the entire listing has been entered and checked before using RENUM 10,10.

Printer control commands for font, margin, etc. may be set by your panel switches or a PRINT #7,command-sequence for your particular printer may be inserted at line 1300 after an OPEN #7,ser1. Be sure to end this sequence with a CLOSE #7.

TV MODE 8 (40-column display with two screens) is assumed so you may wish to adust some of the PRINT and 10 sets black PAPER and white INK for the #2 main display screen and white PAPER and black INK for the #0 editing window. This gives a crisper display on B&W TVs and composite monochrome monitors than the power-up colors. Just use 10 GO TO 510 here if you prefer to Keep the original screens.

Note that in lines 130-200 you may use apostrophes rather than quotation marks to define character-strings. The QL accepts either. The apostrophe is a little handier as it requires no SHIFT, but for clarity and of course for T/S translation the quotes should be used. The reverse slash \ used by the QL for a line feed corresponds to the apostrophe for the T/S. PAUSE without a given value is the same as T/S PAUSE 0.

A little surprise for T/S users (that users of many other computers have had to reckon with all along) is that it cannot be taken for granted that dimensioning a numeric array as DIM a(n) always sets every element to 0. Neither does DIM a$(n) set every string element to a space or CHR$(32). The DIM sets the string array elements to CHR$(0), and then if LET a$(n)=”” is used they become spaces. If no Key is depressed, CODE(INKEY$) also returns 0. This is the reason for the value-checks shown in 210, 610, and 810.

The IF-THEN structure of the QL allows nested test-statements, with ELSE alternative conditions that are active when IF conditions are not met, as in 330 and 350. 350 could also have additional statements appended such as ELSE OPEN #7,scr: INK #7;7 (which sets scr INK to white or the color of your choice). The end of a particular set of IF-THEN-ELSE statements is marked by an END IF to indicate that set of conditions no longer apply to what follows.

The SELect ON sequences in 370-430 and 630-740 may be translated as IF-THEN statements for the T/S. Beta Basic (BB) provides the ELSE function and also has an ON command that would require this change:

610 LET m$=INKEY$, m=VAL m$+1: IF m$="" THEN GO TO 610

This allows lines 630-730 to be entered as only one line to use the BB ON function:

 630 ON m: GO TO 770: GO TO 790: GO TO 970: 110: GO SUB
20: GO TO 1210: GO TO 1320: GO TO 1420: GO TO 1310: SAVE
"addrfile" LINE 10.

Lines 1330-1510 show how the QL sends and receives data to and from devices such as microdrives, modems, printers, networks, etc. For the T/S all this SAVE and LOAD footwork can be replaced by the simple commands SAVE “name” DATA f$() and LOAD “name” DATA f$(). If LET f$(400, TO 3)=STR$ last is inserted before the data save, then LET last=VAL f$(400, TO 3) would re-define the value of last after the loading of new data. (The QL has no VAL function.)

LISTING 2 gives a search routine for T/S users. When using it, the target-line to be searched is first marked by number, then any consecutive set of characters found at the very beginning of that line may be used as a search-word. Either a hard-copy printout or screen display may be selected. Line 350 could be changed to IF y$=”y” THEN OPEN #2,”P” and make 470 CLOSE #2 to direct the PRINT output of lines 380-460 to a printer or to the screen if y$=”n”. IF-THEN statements would then be substituted in 380-420, and the #7 omitted. In BB an ON command-sequence could be used here if 360 is made LET p=CODE f$(n)-48 so the number-sequence 1-9 is produced.

In BB the sort routine at 30-90 may be replaced by the simple command: 30 SORT f$(1 TO last)(21 TO 40) which will re-order 150 array elements by last names in just over 1 second. The QL search routine would be replaced by the following in BB:

130 INPUT " LPRINT y/n? ";y$
140 INPUT "CHR$ in search-word (#=wild): ";c$
150 FOR n=1 TO last
160 LET p$=f$(n)
170 IF INSTRING(1,p$,c$) THEN PRINT n'f$(n, TO 94)'f$(
n,95 TO 114): IF y$="y" THEN GO SUB 350
180 NEXT n
280 PRINT #0;"SEARCH complete": PAUSE 300: GO TO 500

INARRAY would search the entire f$ array but line 150 allows INSTRING to search one array element at a time. Most BB commands and functions allow similar savings in memory-usage as well as processing time which offsets to a great extent the limitations imposed by the 22K free memory remaining with BB in-residence. About 150 file-items may be handled by this program using BB in a Spectrum-emulated TS2068.

In edit mode, ENTER scrolls through the file items. Entering “%” will delete that item, or if a number is entered then that line-item may be re-entered as desired. If more than one line is to be changed the “6” repeat option may be used at the end of the edit mode sequence, or else it might be simpler to use “%” to delete that whole item, then go to the “Additional entries” mode from the main menu. While entering new file items, if $TO is entered instead of an ID or phone no. then that entire file-item may be re-entered to correct an error, or else you can wait and use the “List & edit mode” from the main menu.

Again BB has a much easier way of editing an entire array element at a time by replacing lines 1000-1200 with simply 1000 EDIT f$(n) and 1010 NEXT n. The entire file item is brought back into edit mode for revisions by moving the cursor up and down as well as horizontally through it, just as when it was originally entered. Keying ENTER scrolls through the file.

The “SAVE file” and “LOAD file” modes require a cartridge in mdv1 (or mdv2 with required changes in listing) so that the CAT routine may list all files already on the cartridge. This allows checking file names already in use to avoid overwriting any you wish to Keep. Since I have TKT installed which doesn’t require the DELETE mdv1_name before saves, the very first save you make of the listing (and the save of a file using a given name for the first time) may require adding an optional procedure without the DELETE on unexpanded QLs to provide for such saves. If a save is being made with the same name as an existing file without preceding it with the DELETE MDV1_name command, TKT users receive a warning prompt and the “Y/N” option to abort or proceed.

I think the remaining program REMarks and prompts should be self-explanatory, but then I’m looking at it through different eyes than someone seeing it for the very first time, so feel free to bring any errors or unclear points to my attention. For reply please enclose a SASE. I have written an all Beta Basic version of this program which will appear in a future SYNCWARE NEWS if all goes well.

It would serve a real need, I believe, if QL, T/S, and BB users would send in your own programming hints, especially those procedures and functions you have created, so they can be shared here in UPDATE with other users. And be sure to let Bill and his advertisers Know you appreciate their support. As Rod Gowen of RMG ENTERPRISES, one of the very supportive surviving T/S venders, stated in recent correspondance with me, “We Sinclair users have to stick together!”

LISTING 1 – QL ADDRESS FILE

LISTING 1 - QL ADDRESS FILE, lines 10-150
LISTING 1 – QL ADDRESS FILE, lines 10-150
LISTING 1 - QL ADDRESS FILE, lines 160-810
LISTING 1 – QL ADDRESS FILE, lines 160-810
LISTING 1 - QL ADDRESS FILE, lines 810-1190
LISTING 1 – QL ADDRESS FILE, lines 810-1190
LISTING 1 - QL ADDRESS FILE, lines 1200-1550
LISTING 1 – QL ADDRESS FILE, lines 1200-1550

LISTING 2 — T/S Search Routine

LISTING 2 -- T/S Search Routine, lines 130-210
LISTING 2 — T/S Search Routine, lines 130-210
LISTING 2 -- T/S Search Routine, lines 220-335
LISTING 2 — T/S Search Routine, lines 220-335

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.