home *** CD-ROM | disk | FTP | other *** search
- This database program displays brief instructions
- and asks for your text input. Everything you type
- BEFORE the last character on a line is considered
- data. The LAST character is the COMMAND. Thus what
- you type resembles an English sentence.
-
- * End your line with a period, and the data is
- written to the file.
-
- * End with a ? and a text search starts.
-
- * Type just a ? for a full listing of the file.
-
- * Type just a @ to quit.
-
- An example RUN is included below. Text the user
- types follows the > prompt. The computer response
- is on the next line(s) and explanations are inside
- <brackets>.
-
- RUN
- <file is created>
- > COMAL is nicer than BASIC.
- <text is added to file>
-
- > Len Lindsay is Captain COMAL.
- <text is added to file>
-
- > nicer?
- COMAL is nicer than BASIC.
-
- > Len Lindsay: 608-222-4432.
- <text is added to file>
-
- > COMAL?
- COMAL is nicer than BASIC.
- Len Lindsay is Captain COMAL.
-
- > ?
- freeform.dat.
- Demo.
- COMAL is nicer than BASIC.
- Len Lindsay is Captain COMAL.
- Len Lindsay: 608-222-4432.
-
- > @
- <program ends>
-
- Read the directions after the program listing for
- info on how to enter this same exact program into
- ANY COMAL. (hint: line numbers are required for
- COMAL programs, but AUTO will provide them for you
- as you type):
-
- PAGE // clear the screen
- PRINT "Free Form Database by Joel Rea"
- PRINT "Last character is the command:"
- PRINT " . -- add to file,"
- PRINT " ? -- search file,"
- PRINT " @ -- exit program."
- DIM line$ OF 80, text$ OF 80
- DIM filename$ OF 20, command$ OF 1
- filename$:="freeform.dat"; num=7 // file specs
- filecheck(filename$,num) // if file not exist,
- create it
- REPEAT
- get'line'from'user
- CASE command$ OF
- WHEN "." // period
- add'line'to'file
- WHEN "?"
- display'matches
- OTHERWISE
- NULL // do nothing
- ENDCASE
- UNTIL command$="@"
- END // optional end statement
- //
- PROC get'line'from'user
- PRINT // blank line
- REPEAT
- INPUT "> ": line$ // user types in something
- max:=LEN(line$) // length of input
- UNTIL max>0 // must enter something
- command$:=line$(max:max) // just last character
- IF max>1 THEN // more than just a command
- line$:=line$(1:max-1) // remove last character
- ELSE
- line$:="" // only a command, no other text
- ENDIF
- ENDPROC get'line'from'user
- //
- PROC add'line'to'file
- OPEN FILE num,filename$,APPEND
- WRITE FILE num: line$
- CLOSE FILE num
- ENDPROC add'line'to'file
- //
- PROC display'matches
- OPEN FILE num,filename$,READ
- WHILE NOT EOF(num) DO
- READ FILE num: text$
- IF line$="" OR line$ IN text$ THEN
- PRINT text$,"."
- ENDIF
- ENDWHILE
- CLOSE FILE num
- ENDPROC display'matches
- //
- PROC filecheck(filename$,filenum) CLOSED
- TRAP // check if the file exists
- OPEN FILE filenum,filename$,READ //try opening
- HANDLER //if file doesn't exist drop down here
- OPEN FILE filenum,filename$,WRITE //create it
- WRITE FILE filenum: filename$,"Demo" //1st rec
- ENDTRAP
- CLOSE FILE filenum //close file from either open
- ENDPROC filecheck
-
- HOW TO DO IT...
-
- It is easy to enter a COMAL program. COMAL helps
- you out every step of the way. Before you start a
- new program, erase any current program. Type:
-
- NEW <Enter>
-
- After each line, hit the <Enter> key.
-
- COMAL programs require line numbers. However, we
- list them without line numbers since you can use
- AUTO mode to enter the program. Type:
-
- AUTO
-
- COMAL will respond with:
-
- 0010 *
-
- The cursor (shown above as *) is after the line
- number 10. You just type the first program line
- and hit <Enter>. COMAL then prompts you with the
- next line number:
-
- 0020 *
-
- (Again, the * represents your cursor.) Type each
- line in the program in this manner. COMAL will
- help you. Don't type in the spaces to indent the
- lines. COMAL does that automatically for you. No
- need to capitalize the keywords. COMAL will do
- that for you too. Don't type the name after
- ENDPROC. COMAL will add it for you later. If you
- make a mistake, COMAL will offer you advice.
-
- After typing all the lines, stop AUTO mode
- pressing the <ESC> key.
-
- Before you try out the program store it on disk to
- be safe. If anything goes wrong (lightning
- strikes), you can reload the program from disk.
- Type:
-
- SAVE "freeform"
-
- Now run the program (see sample run earlier in
- this article). Make sure you have the program in
- memory before continuing!
-
- ROUTINE STEALING!
-
- This is a COMAL specialty. It is easy for you to
- steal routines (called procedures or functions)
- from other COMAL programs, and merge them into a
- new program you are writing!
-
- To do this just store the routine to disk in ASCII
- text form (with the LIST command). To merge it
- with a future program use the MERGE command. As an
- example let's store the procedure FILECHECK:
-
- LIST filecheck "filecheck"
-
- PHONE BOOK, PHASE 1...
-
- Now you are ready to try the second program, doing
- some routine stealing! First erase the current
- program. Type:
-
- NEW
-
- As before, the AUTO command gives you line
- numbers. Type:
-
- AUTO
-
- Now just enter the program as shown just below.
- When you get to the end, stop AUTO mode by
- pressing the <ESC> key.
-
- Now we will merge the routine we are stealing from
- Free Form Database. Type:
-
- MERGE "filecheck"
-
- COMAL will automatically renumber the lines as
- they are merged into the program!
-
- The program is now ready to SAVE and RUN. However,
- to satisfy your curiosity, list it to see the
- merged procedure:
-
- LIST
-
- ELECTRONIC PHONE BOOK
-
- DIM name$ OF 20,phone$ OF 12
- DIM filename$ OF 20
- filename$:="phone.dat";num:=5//filespec
- filecheck(filename$,num) // check on file
- REPEAT
- PRINT "e=enter f=find l=list q=quit"
- CASE INKEY$ OF
- WHEN "e","E"
- enter'name
- WHEN "f","F"
- INPUT "What name? ": name$
- search'for(name$)
- WHEN "l","L"
- search'for("")
- WHEN "q","Q"
- END // This ends the program here!
- OTHERWISE // not valid key
- PAGE // clear the screen
- ENDCASE
- UNTIL TRUE=FALSE // forever
- //
- PROC enter'name
- INPUT "Enter name: ": name$
- IF name$>"" THEN //name required
- INPUT "Enter phone: ": phone$
- add'to'file
- ENDIF
- ENDPROC enter'name
- //
- PROC add'to'file
- OPEN FILE num,filename$,APPEND
- WRITE FILE num: name$,phone$
- CLOSE
- ENDPROC add'to'file
- //
- PROC search'for(search$)
- OPEN FILE num,filename$,READ
- WHILE NOT EOF(num) DO
- READ FILE num: name$,phone$
- IF search$="" or search$ in name$
- PRINT name$,TAB(21),phone$
- ENDIF
- ENDWHILE
- CLOSE
- PRINT "Hit <Enter> when ready."
- WHILE inkey$<>chr$(13) DO NULL
- ENDPROC search'for
- <stop AUTO mode here, press <Esc>
-
- Here's a sample of what it does:
-
- RUN
- e=enter f=find l=list q=quit
- e
- Enter name: Captain COMAL
- Enter phone: 608-222-4432
- e=enter f=find l=list q=quit
- e
- Enter name: Emergency
- Enter phone: 911
- e=enter f=find l=list q=quit
- l
- phone.dat Demo
- Captain COMAL 608-222-4432
- Emergency 911
- Hit <Enter> when ready.
- e=enter f=find l=list q=quit
- f
- What name? COMAL
- Captain COMAL 608-222-4432
- Hit <Enter> when ready.
- e=enter f=find l=list q=quit
- q
-