The Cable Column: Programming in Archive

See all articles from Update April 1989
Author(s): Bill Cable
Publication: Update Magazine
Pub Details: Update April 1989
Date: April 1989
Pages: 29-31

WOOD AND WIND COMPUTING
Bill Cable : RR 2 Box 92 : Cornish, NH 03745 : 603 675 2218

PROGRAMMING IN ARCHIVE

In the last 2 issues of UPDATE you were introduced to ARCHIVE, the excellent database program supplied with every QL. You were encouraged to try it if you haven’t already because almost every computer user has applications that involve the storage and retrieval of information. When you load ARCHIVE, your QL becomes a powerful information handling machine. The IBM version of ARCHIVE (PC-FOUR for $99) is just like our QL ARCHIVE. In fact these articles can be used as tutors for IBM clone users who have it and these programs will work on their IBM machines. So ARCHIVE can be used on millions of machines.

You will find that although ARCHIVE is very powerful it is not convenient to use unless you put the tasks you want to accomplish in programs so you can quickly call them up and execute them. What a drag you say. Well you can purchase quality ARCHIVE based programs for specific applications that don’t require knowledge of ARCHIVE programming. But have you tried the language? It is a very nice language and its implementation on the QL is very efficient and well behaved. The ARCHIVE language is a procedure oriented language like SUPERBASIC but without line numbers. When you write a program in ARCHIVE you make a series of procedures. These are blocks of code with a name. When you need the task done that the procedure provides you simply use its name. That part of the program will be executed and you will return to where you were.

How can you keep track of your program without line numbers you ask? ARCHIVE has a nice built-in program editor (think of it like a word processor for writing programs) just for that purpose. It does it all for you automatically. When you enter the program edit mode any loaded procedures are listed alphabetically on the left side of the screen. The procedure being edited is in bold face and its lines appear on the right. You change which procedure to edit by pressing <TAB> or <SHIFT><TAB>. You choose your edit location within the procedure’s lines (on the right) by the up arrow and down arrow keys. You do your editing at the bottom of the sceen. It very convenient and much easier than SUBPERBASIC program editing. The editor automatically indents conditional statements and loops for easy reading. Because the language has very good error messages, giving procedure name and the line where the error occurs and the editor is so quick at hand you can debug very fast.

So let’s try entering a small program called ‘e’ which allows us examine a database with single key presses. You can try it on the gazet database provided with ARCHIVE. You can easily customize it for your own purposes. This exercise will introduce you to ARCHIVE programming. We won’t worry about how the program works but rather the more basic skill of how you enter and edit a program. Have the ARCHIVE section of your user’s manual open. You can look up the commands and functions there for more detail. At the end of the article is a list of the the commands you should be familiar with for program editing in ARCHIVE. Keep it handy as a quick reference.

ENTERING AN ARCHIVE PROGRAM

Below I will go through all the keystrokes necessary to enter a short but useful program that consists of 2 procedures. One procedure is called ‘e’ for examine and the other ‘sfind’ for string find. What you should type in will be in bold and my comments with be in {},<ENTER> means press the ENTER key. Most of the editing takes place at the bottom of the screen. If you make a detectable typo the editor will reject your line and force you to redo it. Otherwise correct mistakes after you enter the procedures.

Start up ARCHIVE by resetting and putting the DATABASE (ARCHIVE) cartridge in mdv1_ and pressing <F1>. ARCHIVE loads and we are in command mode. Put a formatted cartridge in mdv2_ to save the finished program to. We will activate the program editor, enter our 2 procedures, save the program, and run it. Watch the top screen boxes as they tell you what to do also.

edit<ENTER>               {activate the program editor}

The editor activates. No procedures are loaded and the editor prompts for the name of our procedure. Type in its name and then the lines of the procedure.

e<ENTER>                  {name of this procedure}

cls<ENTER> {lines of the 'e' procedure}
input at 2,1;"Look at which database [device_name] : ";ans$<ENTER>
look ans$<ENTER>
mode 0<ENTER>
display<ENTER>
let c$=""<ENTER>
while c$<>"e"<ENTER>
sprint<ENTER>
print at 14,58;"KEY OPTIONS ";recnum();" "; at 15,60;"b back";<ENTER>
print at 16,60;"n next"; at 17,60;"f first"; at 18,60;"l last"<ENTER>
print at 19,60;"s string find"; at 20,60;"c continue"<ENTER>
print at 21,60;"e exit";at 23,58;"** press a key **"<ENTER>
let c$=getkey()<ENTER>
let c$=lower(c$)<ENTER>
print at 23,50;rept(" ",30)<ENTER>
if c$="b": back : endif<ENTER>
if c$="n": next : endif<ENTER>
if c$="f": first : endif<ENTER>
if c$="l": last : endif<ENTER>
if c$="s":sfind: endif<ENTER>
if c$="c": continue : endif<ENTER>
endwhile<ENTER>
close<ENTER>
mode 1<ENTER>

We are done with our first procedure. To end it press :

<ESC>                     {end entering first procedure}

We will now make one more procedure. To create a new procedure type :

<F3>n                          {edit command for new procedure}
sfind<ENTER> {new procedure name}

print at 23,50;rept(" ",30)<ENTER> {lines of the sfind procedure}
input at 23,50;"Find what : ";i$<ENTER>
if i$<>"": find i$: endif<ENTER>
print at 23,50;rept(" ",30)<ENTER>
if not found(): print at 23,60;"Not found": endif<ENTER>

We are done entering the 2nd procedure so let’s exit from inserting

<ESC>                     {exit from inserting lines}

Now let’s exit from the program editor and save our program and print it out.

<ESC>                     {exit from the program editor to ARCHIVE command mode}
save "mdv2_eprog"<ENTER> {actually saved as mdv2_eprog_prg}
llist<ENTER> {do only if you have a printer and put if online}

Now let’s run it.

e<ENTER>                  {activate the e procedure}
mdv1_gazet<ENTER> {our program prompts for a database, let's use gazet}

Now play with the menu options. If everything works well you have done good. If you get an error, note where it occured and the error message and type :

close<ENTER>              {close database if left open by the error}
mode 1<ENTER> {mode 1 has upper display box visable}

Check you printout against the instructions above for typos. When you determine the problem use the editor to correct it and rerun it. Program structure fault means if-endif or while-endwhile don’t pair up. Below are the basic commands needed. Don’t forget to save your corrected version.

ARCHIVE PROGRAM EDITING COMMANDS

1. When in ARCHIVE Command mode (not in the ARCHIVE program editor)

Start the editor      edit<ENTER>        {from within ARCHIVE}
Load a program        load "{}"<ENTER>   {where {}=device_name,ie. mdv2_prog}
Save a program        save "{}"<ENTER>   {where {}=device_name,ie. mdv2_prog}
Start a procedure     {}<ENTER>          {where {}=procedure name}
print a program       llist<ENTER>       {list out loaded procedures}

2. When in the ARCHIVE program editor (not in ARCHIVE command mode)

Stop the editor       <ESC> or <ESC><ESC> {returns to ARCHIVE command mode}
Make a new procedure  <F3>n<ENTER>  {new procedure command}
                      {}<ENTER>       {where {}=name for procedure}
                      {enter lines of procedure}
                      <ESC>           {when done}
Move to a procedure   <TAB> or <SHIFT><TAB>  {until its name is in bold}
Move to a line        <up arrow> or <down arrow> {until it is in bold}
Insert new lines      {move to line just above where they go}
                      <F4>            {insert command}
                      {now insert lines}
                      <ESC>           {when done}
Edit a line           {move to the line to be edited with arrow keys}
                      <F5>    {now edit line at bottom of screen,use arrows}
                      <ENTER>         {when line is okay}
Cut (Delete) line(s)  {position on 1st line to be deleted with arrow keys}
                      <F3> c  {cut command}
                      {use up or down arrow to mark those to be deleted}
                      <ENTER> {delete marked lines or <ESC> to abort}
Paste (copy) Lines    {Cut them as above}
                      {move to procedure & line to put them}
                      <F3> p <ENTER> {they will be pasted in place}
Delete a procedure    {Move to procedure to delete by <TAB> & <SHIFT><TAB>}
                      <F3> d <ENTER>          {its gone}

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