Cable Column

See all articles from Update July 1993
Author(s): Bill Cable
Publication: Update Magazine
Pub Details: Update July 1993
Date: July 1993
Pages: 24-25

ARCHIVE SERIES PART 13 : ENTERING PROCEDURES USING THE ARCHIVE PROGRAM EDITOR – SECOND GROUP

We have one more procedure (by_arrow) to be added to the ones entered last time. It allows for selecting among options displayed on the screen by moving an arrow to the desired option and then pressing <ENTER>. The arrow can be moved by the arrow keys (up, down, right, left) or by the number keys (1-9) or by a designated character for each option. This will give a quasi graphical face to our ARCHIVE programs and completes our basic user interface module we will call group2 to be used with all programs to follow.

Before getting into that I want to share my impressions of the “MIRACLE in NEWPORT” event that I just returned from. For those of us QL people lucky enough to be there it was very sweet. There was an impressive collection of talented people from all over the US and Canada and the UK right there in one spot for a period of several days. You could walk right up to the expert in whatever field interested you and start asking questions. I arrived on Friday and regrettably had to leave after the Saturday night dinner but I am sure much fun was had during the following day or so. Bob Dyl and the IQLR Group did an excellent job in planning and support. The number of people attending was not large (I heard estimates of about 60 people) but it was the most dense QL atmosphere ever to occur in North America. There is talk of doing it again and I hope it becomes a yearly event.

Most of my effort during the festivities went into demonstrating QLerk (my home and small business financial program for the QL (written in ARCHIVE naturally). It is now officially for sale although I am going to remain low key about it for a couple of months until I get more feedback from those now in possession of it and have time to expand the users manual. Eventually I will send out a mailer and advertise widely. For anyone who can’t wait and wants to be among the first to use it, you can order it from me : Bill Cable, Wood and Wind Computing, RR3 Box 92, Cornish, NH 03745 for $75.

PREPARATION

Start ARCHIVE in your customary way so you see the ARCHIVE command prompt (>). We will not need to access a database. You will start the editor and load the group of procedures entered last time and saved in a file called “group1”. Then we will start the editor and begin entering the new procedure called “by_arrow”. And we will also enter a testing procedure called “test” to illustrate how the new procedure can be used. If you make a mistake while entering the listing below the editor may not accept the line and you will have to spot the mistake and correct it (like unmatched quotes). Also the indention’s should match the listing if there are no mistakes. Type in as much as you wish at one time and exit the editor and save the file with the name group2 and save a second copy somewhere else. Remember to load group2 when you are ready to continue your work. Notice that in the “test” procedure the screen is first setup then the “by_arrow” procedure is called with the necessary information on where the arrow can be moved to make a choice. The “by_arrow” procedure returns a value in the variable “ans” which will indicated which choice was made. If a 0 is pressed no <RETURN> is needed and it can be treated by the programmer as desired. Most likely you will have mistakes to correct (debug). The basic steps are :

load "{}group1"<ENTER>          Load previous work {}=device
edit<ENTER>                     Start editor
<F3>n                           New procedure
by_arrow;sl,nl,sc,nc,bw,s$,ap<ENTER>   New name
{enter lines of by_arrow listed below}
<ESC>                           Exit adding new procedure
<F3>n                           New procedure
test<ENTER>                     New procedure name-
{enter lines of test listed below}
<ESC><ESC>                      Exit adding and editor
save "{}group2"<ENTER>          Save work {}=device
test<ENTER>                     Try test procedure (play)

BY_ARROW AND TEST PROCEDURE LISTINGS

proc by_arrow;sl,nl,sc,nc,bw,s$,ap
rem
rem Choose by moving arrow over options drawn on screen and pressing <ENTER>
rem
rem Passed arguments defining screen area in blocks of rows and columns
rem sl - start line, nl - number of lines
rem sc - start column, nc - number of columns
rem bw - block width for choices on screen
rem s$ - string of key characters, ap - at position (between 1 and nl*nc)
rem
rem Local internal variables
rem nl - becomes end line number, al - at line (current line)
rem ac - at column (current column), ll - last line position
rem lc - last column position, es - length of key string
rem i$ - key press character, i - key press character ASCII code
rem k - acceptable key press flag
rem
rem Global returned variable
rem ans - returns choice value as position in s$ or 0
rem
local al,ac,ll,lc,es,i$,i,k
let nl=sl+nl-1
print rv$;
let al=sl+int((ap-1)/nc): let ac=sc+((ap-(al-sl)*nc)-1)*bw
let ll=al: let lc=ac: print at al,ac;chr(14);"→";: let es=len(s$) *** right arrow is <CTRL> ]
let k=0: while k<>30 and k<>48: let i=0: let i$=upper(getkey())
if ap<es: let k=instr(s$(ap+1 to es),i$): else : let k=0: endif
if not k: let k=instr(s$,i$): else : let k=k+ap: endif
if not k: let i=code(i$): if i>48 and i<58: let k=i-48
if k>len(s$): let k=0: endif : endif : endif
if k: let al=int((k-1)/nc+1): let ac=(k-(al-1)*nc)*bw+sc-bw: let al=al+sl-1
else : if i=30 or i=48: let k=i
else : if i=2: let k=i: let al=al-1
if al<sl: let al=nl: endif : else : if i=3: let k=i: let al=al+1
if al>nl: let al=sl: endif
else : if i=4: let k=i: let ac=ac+bw
if ac>sc+bw*(nc-1): let ac=sc: endif
else : if i=5: let k=i: let ac=ac-bw
if ac<sc: let ac=sc+bw*(nc-1): endif
endif : endif : endif : endif : endif : endif
if ll<>al or lc<>ac: print at ll,lc;" ";: let ll=al: let lc=ac: endif
let ap=(al-sl)*nc+(ac-sc)/bw+1
if k: print at al,ac;"→";: else : print at al,ac;"?";: endif : endwhile *** right arrow is <CTRL> ]
if k=48: print at al,ac;"0";rv$;chr(15);
else : print at al,ac;"+";rv$;chr(15);: endif
let al=al-sl+1: let ac=(ac-sc)/bw+1:rem let ans=10*al+ac
if k=48: let ans=0: else : let ans=ap: endif
endproc

proc test
mode 0:setup
let x$=" Apple Banana Cherry Corn Eggplant "
let y$=" Carrot Peach Lemon Beet eXit "
print at 10,1;rv$;"Food : ";x$; at 11,8;y$;rv$;
by_arrow;10,2,8,5,10,"ABCCECPLBX",2
if ans=10 or ans=0: mode 1: stop : endif
let x$=x$+y$: let i$=x$((ans-1)*10+1 to (ans-1)*10+10)
acky;14,"You picked option "+str(ans,2,0)+". Yummy"+i$
test
endproc

You should do some experimentation with the procedures introduced so far to make sure you understand how they work. Remember to activate the “setup” procedure first either in a procedure as I have done in “test” or directly at the command prompt. Debugging your typos can be time consuming but the error messages are good. Refer to their descriptions in your manual. Giving incorrect arguments for procedures also leads to errors.

The ARCHIVE Language once learned is fast for program development but has relatively slow screen displays. I have found the “by_arrow” procedure to be one way to have a nice prompting screen that works quickly. If you have any suggestions for improving these procedures please let me know. Until next time when we finally introduce a complete program, Happy Archiving!

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