Cable Column

See all articles from Update April 1993
Author(s): Bill Cable
Publication: Update Magazine
Pub Details: Update April 1993
Date: April 1993
Pages: 37-38

ARCHIVE SERIES PART 12 : ENTERING PROCEDURES USING THE ARCHIVE PROGRAM EDITOR – FIRST GROUP

This series now begins formal programming in ARCHIVE. I have provided many one liner type-in examples in the past as a way to illustrate how some of the commands work but ARCHIVE is not designed to be used that way. The commands are just the building blocks of a more complex structure called a procedure. ARCHIVE is a procedure based language like SuperBASIC.

What is a procedure? It is just a user defined collection of ARCHIVE commands and functions (and perhaps calls to other procedures) that accomplishes a task. The procedure is given a name and it is executed (called) when the procedure name is invoked. Procedures are similar to functions or subroutines in other languages. They work similar to GOTOs in older version of BASIC where a block of code could be jumped to and returned from. Procedures have several advantages over the GOTOs. First the name of the procedure, if wisely chosen, is descriptive of what the procedure does That helps us conceptualize what is being done much better than line numbers. It makes it possible to read a program and actually understand most of it. Second procedures can be developed and debugged independently and then be merged into whatever programs need the procedure. Third a procedure can call itself. Often certain programming tasks have a simple solution if a group of statements can be used over and over (recursion) until a condition is met. Often we want our procedure to be passed information to work with. This is done by putting a semicolon after the procedure name and listing the variables (arguments) to be passed separated by commas. If we define our procedure in this way the arguments must always be included when the procedure is called.

What is a program in a procedure based language? A procedure is a collection of commands,functions, and procedure calls with a name and specific task to accomplish, a program is a collection of procedures stored in a file (which has a name) that work together to accomplish a more complex task.

What is a function in the ARCHIVE language? Functions are much like procedures but there is only a fixed set of system defined ones provided and they always have an argument list in parenthesis (). They might be thought of as useful canned procedures always available to us.

I have explained previously that ARCHIVE supports 2 kinds of variables much like BASIC : Text variables which end in a ‘$’ and can hold up to 255 characters and floating point (numeric) variables which don’t end in ‘$’ and have up to 14 significant digits. ARCHIVE does not support arrays. Variables must be initially defined before they can be used and there are 3 ways this can be done :

1. LET command :            let a$ = "Hello" : let bet = 543
2. LOCAL command :          local a$,bet
3. In procedure definition : proc tally_up;a$,bet

Variables can be global (available everywhere) or local (exist temporally within a procedure). They are local within a procedure if in the procedure definition or in a LOCAL command within the procedure otherwise they are global.

We will continue learning about ARCHIVE by entering and playing with a series of procedures that can be saved and merged into programs as needed. These handy procedures deal primarily with displaying information to the user and prompting for information from the user. By having these standardized procedures for interacting with the user it will be much easier to construct the more complex programs I will introduce later.

BASICS OF THE ARCHIVE PROGRAM EDITOR

After you start ARCHIVE you are in command mode and you see the command prompt ‘>’. These are the ARCHIVE commands relating to the program editor available in the command mode :

Start the editor              edit<ENTER>
Load procedure(s)             load "{}name"<ENTER>
Save procedure(s)             save "{}name"<ENTER>
Start a loaded procedure      name<ENTER>
print loaded procedures       llist<ENTER>
                  where {} = device (flp2_,mdv1_. etc)

When you save procedures to a file they are in ASCII (text) form which can be edited with other editors (I like THE EDITOR). There is a binary form ‘save object’ and ‘load object’ which will be discussed later.

After you start the ARCHIVE program editor (by typing : edit<ENTER>) you are in the program edit mode. The program editor is like a single purpose word processor designed to only create and edit ARCHIVE procedures. I think it is one of the slickest programming environments around. If it only had a search and replace it would be complete. If no procedures are currently loaded you will be asked for a name of a procedure to create otherwise all 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 screen. It very convenient and much easier than SuperBASIC program editing. The editor automatically indents conditional statements and loops for easy reading and debugging.

The program editor has its own set of commands and special keys. They are :

Exit the editor          <ESC> or <ESC><ESC>
Create procedure         <F3>n<ENTER>
                         name<ENTER>
                          {enter lines of procedure}
                         <ESC>          {when done}
Move to a procedure      <TAB> or <SHIFT><TAB>
Move to a line           <up arrow> or <down arrow>
Insert new lines         <F4>
                           {now insert lines}
                         <ESC>              {when done}
Edit a line              <F5>
                           {edit line as desired}
                         <ENTER>            {when done}
Cut (Delete) line(s)     <F3> c
                           {up or down arrow for more}
                         <ENTER> or <ESC> to abort
Paste (copy) Lines         {Cut them as above}
                          {move to procedure & line to put}
                         <F3> p <ENTER>
Delete a procedure        {Move to procedure to delete}
                         <F3> d <ENTER>       {its gone}

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 immediately begin entering the procedures listed below. Some mistakes will cause the editor to not accept a line and you will have to spot the mistake and correct it (like unmatched quotes). Type in as many as you wish and exit the editor and save them to a file (call it group1) and save a second copy somewhere else.

PROCEDURES TO ENTER – GROUP 1

proc acky;line,m$
rem prints message (m$) at line & waits for acknowledge
liny;line: print m$;"."; tab 40;" Press <ENTER> : ";
input i$:liny;line
endproc
proc defy;line,m$,d$
rem prompts m$ at line and suggests d$, \ = null
liny;line: print m$;" [<ENTER> if '";d$;"'] : ";:inp: if ans$=""
let ans$=d$: endif : if ans$="\": let ans$="": endif
print at line,len(m$)+1;" : ";rv$;" ";ans$;" ";rv$; tab 80;
let ans$=lower(ans$)
endproc
proc heady;i$
rem clears screen and makes makes heading of i$
paper sp: cls : paper hp: ink hi
print rept(" ",240); at 1,1;i$;
paper sp: ink si: print at 4,0;
endproc
proc inp
rem inputs global variable ans$ in reverse screen color
print rv$;: input " ";ans$;" ";: print rv$;
endproc
proc inpy;line,m$
rem prompts m$ at line and inputs (through inp) ans$
liny;line: print m$+" : ";:inp: let ans$=lower(ans$)
endproc
proc key_choice;i,i$,j$,k$,l$
rem prompts i$,j$,k$ at line i, accepts a single key input
rem if in l$ list, if ke=1 need enter if ke=0 don't
let ans$="": while not instr(l$,ans$) or len(ans$)<>1
print at i,0; tab 80; at i,0;i$;ke$;j$;" => ";k$;" : ";rv$;" ";
if ke: input ans$;: print " ";rv$;: let ans$=lower(ans$)
else : let ans$=lower(getkey())
if code(ans$)<32: if code(ans$)=2: let ans$=""
else : if code(ans$)=3: let ans$=""
else : if code(ans$)=4: let ans$="": else : if code(ans$)=5
let ans$="": else : let ans$="": endif : endif : endif : endif
endif : print ans$;" ";rv$;: endif
if not instr(l$,ans$) or len(ans$)>1: if ke
let ans$=" then <ENTER>": else : let ans$="": endif
print at i,0;rv$; tab 80;
acky;i,"Press the SINGLE KEY for the desired action"+ans$
print rv$;: endif : endwhile
endproc
proc liny;line
rem clears line at line
if line: print at line,0;tab 80;: print at line,1;: else : print :
endif
endproc
proc msg;line,m$
rem prints pausing message m$ at line
liny;line: print "{"+m$+"...}";
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 ke = 1 :let ke$ = " KEY+ENTER "
endproc
proc yorn;line,m$
rem prompts m$ at line returns y or n in ans$
let ans$="": while ans$<>"y" and ans$<>"n":liny;line
print m$+" [ y/n ] : ";:inp: let ans$=lower(ans$): endwhile
endproc

There is not much space for examples but try these :

mode 0 : setup<ENTER>    always initialize setup first
yorn;10,"Are you happy" : print at 18,1;ans$<ENTER>
defy;12,"Your favorite computer","QL":
print at 20,1;ans$<ENTER>
key_choice;14,"","Device","Mdv Flp Ram eXit","dfrx"
:print at 22,1;ans$<ENTER>

Notice that global variable ans$ is often used to hold the procedure result. Always run setup when using these procedures to initialize needed global variables.

Until next time when we have more procedures to enter and more extensive examples Happy Archiving!