![]() |
The following module works on a data file called DATA, containing names, addresses, post codes and telephone numbers. It assumes this file has already been created with a statement like this:
CREATE "DATA",A,nm$,ad1$,ad2$,ad3$,ad4$,tel$
To use a database created with the Data application, see Database manipulation.
The first procedure is the controlling, calling procedure, offering you choices. The next two let you add or edit records.
PROC files:
GLOBAL nm$(255),ad1$(255),ad2$(255)
GLOBAL ad3$(255),ad4$(255),tel$(255),title$(30)
LOCAL g%
OPEN "DATA",A,nm$,ad1$,ad2$,ad3$,ad4$,tel$
DO
CLS
dINIT "Select action"
dTEXT "Add new record","",$402
dTEXT "Find and edit a record","",$402
g%=DIALOG
IF g%=2
add:
ELSEIF g%=3
edit:
ENDIF
UNTIL g%=0
CLOSE
ENDP
PROC add:
nm$="" :ad1$="" :ad2$=""
ad3$="" :ad4$="" :tel$=""
title$="Enter a new record"
IF showd%:
APPEND
ENDIF
ENDP
PROC edit:
LOCAL search$(30),p%
dINIT "Find and edit a record"
dEDIT search$,"Search string",15
IF DIALOG
FIRST
IF FIND("*"+search$+"*")=0
ALERT("No matching records")
RETURN
ENDIF
DO
nm$=A.nm$ :ad1$=A.ad1$ :ad2$=A.ad2$
ad3$=A.ad3$ :ad4$=A.ad4$ :tel$=A.tel$
title$="Edit matching record"
IF showd%:
UPDATE :BREAK
ELSE
NEXT
ENDIF
FIND("*"+search$+"*")
IF EOF
ALERT("No more matching records")
BREAK
ENDIF
UNTIL 0
ENDIF
ENDP
PROC showd%:
LOCAL ret%
dINIT title$
dEDIT nm$,"Name",25
dEDIT ad1$,"Street",25
dEDIT ad2$,"Town",25
dEDIT ad3$,"County",25
dEDIT ad4$,"Postcode",25
dEDIT tel$,"Phone",25
ret%=DIALOG
IF ret%
A.nm$=nm$ :A.ad1$=ad1$ :A.ad2$=ad2$
A.ad3$=ad3$ :A.ad4$=ad4$ :A.tel$=tel$
ENDIF
RETURN ret%
ENDP
|
|