Cable Column

Author(s): Bill Cable
Publication: Update Magazine
Pub Details: Update October 1993
Date: October 1993
Pages: 25-26

ARCHIVE SERIES

PART 14 : ENTERING PROCEDURES USING THE ARCHIVE PROGRAM EDITOR – THIRD GROUP

We are starting to build a large program now. This time I am introducing several new procedures to our basic user interface procedures now saved as group2_prg. We will call this new set which includes all of our group2 plus the new procedures – group3. I am not being specific about what kind of program we are ultimately making because I haven’t made up my mind yet. The procedures we are adding this time are still of a general nature and will be useful in many situations. Feel free to contact me if you have a request for a particular kind of ARCHIVE program to be developed in this column.

PREPARATION

Start ARCHIVE in your customary way so you see the ARCHIVE command prompt (>). You will load the group of procedures entered last time and saved in a file called “group2”. Then we will start the editor and begin entering the first new procedure called “close_all”. You will continue entering the rest of the procedures plus 2 testing procedures called “test2” and “test3” to illustrate how the new procedures 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 group3 and save a second copy somewhere else. Remember to load group3 when you are ready to continue your work. Test2 illustrates the directory related procedures and test3 illustrates the field_display procedure used with the by_arrow procedure entered last time. This allows us to access a particular field of a database using the arrow keys or the first letter of the field name. Most likely you will have mistakes to find (debug). The basic steps are :

load "{}group2"<ENTER>              Load previous work {}=device
edit<ENTER>                         Start editor
<F3>n                               New procedure
close_all<ENTER>                    New procedure name
{enter line of close_all listed below}
<ESC>                               Exit adding new procedure
<F3>n                               New procedure
dcopy;i$,j$<ENTER>                  New procedure name-
{enter line of dcopy listed below}
...... and so on
<ESC> <ESC>                         Exit adding and editor
save "{}group3 <ENTER>              Save work {}=device
test2<ENTER>                        Try test2 procedure (play)
test3<ENTER>                        Try test3 procedure (play)

LISTING OF NEW PROCEDURES TO MAKE GROUP3

proc close_all
while 1: close : endall
endproc
proc dcopy;i$,j$
msg;23,"copying "+i$+" to "+j$: backup i$ as j$
endproc
proc device;i,i$
print at i,0;"For "+i$; tab 80; at i+1,1;rv$;
print " Use : Flp1_ Flp2_ Ram1_ Ram2_ Mdv1_ Mdv2_ Other eXit ";rv$;tab 80;
by_arrow;i+1,1,8,8,8,"FFRRMMOX",8: if ans=1: let ans$="flp1_"
else : if ans=2: let ans$="flp2_": else : if ans=3: let ans$="ram1_"
else : if ans=4: let ans$="ram2_": else : if ans=5: let ans$="mdv1_"
else : if ans=6: let ans$="mdv2_"
else : if ans=7:inpy;i+1," Name the device": else : let ans$=""
endif : endif : endif : endif : endif : endif : endif
endproc
proc directory
device;22,"Directory": if ans$="": return : endif : let d$=ans$
while 1: dir d$: print at 23,1;rv$;" Directory of ";d$;
print tab 22;" : Copy deLete Directory eXit ";rv$; tab 79;
by_arrow;23,1,25,4,12,"CLDX",4: if ans=0 or ans=4: return
else : if ans=1: print at 23,1;rv$; tab 79; at 23,1;" Copy ";d$;
input f$;: print rv$;:device;22,"device to copy "+d$+f$+" to"
liny;22: if ans$<>"": let e$=ans$
print at 23,1;rv$; tab 79; at 23,1;" Copy ";d$;f$;" to ";e$;: input g$;: print rv$;
if g$="": let g$=f$: print rv$;g$;rv$;: endif
error dcopy;d$+f$,e$+g$
if errnum()=21:yorn;23,e$+g$+" already exists. Overwrite"
if ans$="y":dkill;e$+g$: error dcopy;d$+f$,e$+g$: endif : endif
if errnum(): acky;23,"Copy failed. Err No = "+str(errnum(),2,0): endif: endif : let ans=0
else : if ans=2: print at 23,1;rv$; tab 79; at 23,1;"Delete : ";d$;
input h$;: print rv$;: if h$<>"": error dkill;d$+h$: endif : let ans=0
else : if ans=3:directory: return: endif : endif : endif : endif : endwhile
endproc
proc dkill;i$
msg;23,"deleting "+i$: kill i$
endproc
proc erry;l,m$
acky;l,"Error "+str(errnum(),2,0)+" while "+m$
endproc
proc field_display;l$,sl,nl,sc,nc,bw,fw
let n=0: let al=sl: let ac=sc: let cc=1: while n<numfld()
let i$=fieldn(n,l$): if len(i$)>fw-2: let i$=i$(1 to fw-2): endif
if len(i$)=1: let i$=upper(i$): else : let i$=upper(i$(1))+lower(i$(2 to len(i$))): endif
print at al,ac;i$;: let n=n+1: let cc=cc+1
if cc>nc: let ac=sc: let al=al+1: let cc=1: else : let ac=ac+bw: endif: endwhile
endproc
proc looky;d$,l$
msg;23,"look access of "+d$: look d$ logical l$:liny;23
endproc
proc setup
rem sets needed initial values ** must be run first **
let rv$=chr(26): let hp=3: let hi=1: let sp=5: let si=1: let cs$=chr(27)+"B"
let ke=1: let ke$=" KEY+ENTER "
endproc
proc test2
mode 0:setup:directory: mode 1
endproc
proc test3
mode 0:setup: error close_all
let hd$="TEST TO DISPLAY FIELDS OF ANY ARCHIVE DATABASE":heady;hd$
device;4,"Device location of source database. eXit to stop"
if ans$="": mode 1: stop : endif : let sd$=ans$: dir sd$
inpy;23," File name of source database (with extension)": let sn$=ans$
error looky;sd$+sn$,"s": if errnum():erry;23,"accessing "+sd$+sn$: test3: return : endif
msg;23,"checking fields": let l=0: let a$="": while l<numfld()
let i$=fieldn(l): let a$=a$+upper(i$(1)): let l=l+1: endwhile
cls : print tab 30;"PICKING FIELDS of ";sd$+sn$: print rv$;cs$: let n=numfld()
let i=20: if n<41: let j=2: let k=40: else : if n<61: let j=3: let k=26
else : if n<81: let j=4: let k=20: else : if n<101: let j=5: let j=16
else : if n<121: let j=6: let k=13: else : if n<141: let j=7: let k=11
else :acky;23,"Too many fields to display":test: stop
endif : endif : endif : endif : endif : endif
field_display;"s",2,i,1,j,k,k: print rv$;
let ans=1: while 1: print at 22,1; tab 22;"Move arrow to desired field"; tab 79;
print at 23,1; tab 20;"<ENTER> to select or 0 to exit"; tab 79;
by_arrow;2,i,0,j,k,a$,ans: if ans=0: mode 1: stop : endif
if ans<=numfld():liny;22:acky;23,"You chose field "+fieldn(ans-1): endif: endwhile
endproc

The procedure “setup” already existed so you need to alter it to match the new listing. To use “test3” you need a database to inspect. There is a small “bug” in by_arrow you may come across. Next time I will have more procedures. Feel free to contact me if you have problems. Until then, Happy Archiving!

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