home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-385-Vol-1of3.iso
/
t
/
tech91.zip
/
TI662.ASC
< prev
next >
Wrap
Text File
|
1991-08-26
|
5KB
|
199 lines
PRODUCT : Paradox NUMBER : 662
VERSION : 2,3,3.5
OS : PC DOS
DATE : August 26, 1991 PAGE : 1/3
TITLE : Generating Unique Values (Multi User Auto Increment)
; This Method Works for Single or Multi User
;Borrowed in part from the Paradox 3 Developers Toolkit.
;Special Notes : This procedure is very useful for entering a
; new identification number for every new record
; entered into for instance a "Customer" table.
; Because Paradox doesn't have its own auto-
; incrementing feature, this procedure does the
; "trick" for you. Create a one field KEYED
; table such as:
;
; Counter ═╦═ Counter ═╗
; ║ 10001 ║
; ║ 10002 ║
; ║ 10003 ║
; ║ 10004 ║
; ║ 10005 ║
; ║ 10006 ║
; ║ 10007 ║
; ║ 10008 ║
; ║ 10009 ║
; ║ 10010 ║
;
; Upon pressing a designated key, the value
; 10001 is transferred to your "Customer" table
; and the value 10001 is changed to 10011. The
; table is keyed so 10011 goes to the bottom of
; the table and the next available number is
; ready at the top of the table for next time.
; First define a counting procedure and then a user interaction
; for entering data.
PRODUCT : Paradox NUMBER : 662
VERSION : 2,3,3.5
OS : PC DOS
DATE : August 26, 1991 PAGE : 2/3
TITLE : Generating Unique Values (Multi User Auto Increment)
;-----define the procedure COUNTER ----------------------------
PROC counter()
PRIVATE countervar,begintbl
begintbl=Table()
MOVETO "counter" ; On a multitable form the MOVETO command
; here would not work unless the the counter
; table were placed on the multitable form.
; You could place the counter table as an
; unlinked table on the form and the
; MOVETO command would still work. No need
; in this context to first VIEW "counter".
SCAN ; move through table until you can successfully lock
; a record. Ten records in your counter table will give
; you ten chances to successfully lock a record.
LOCKRECORD
IF NOT retval THEN
; NOT retval means could not get a lock, so
LOOP ; go to top of scan loop which goes to next record
ELSE
countervar = [Counter]
[Counter] = [Counter] + 10
; If you have ten records in your counter table then
; increment the current record by ten. With twenty
; records in your counter table increment by twenty,
; etc.
UNLOCKRECORD
QUITLOOP
ENDIF
ENDSCAN
MOVETO begintbl
RETURN countervar
ENDPROC
PRODUCT : Paradox NUMBER : 662
VERSION : 2,3,3.5
OS : PC DOS
DATE : August 26, 1991 PAGE : 3/3
TITLE : Generating Unique Values (Multi User Auto Increment)
;------ Having already defined a counter proc, now set up the
; workspace with the counter and customer tables. If
; using a multitable form no need to VIEW "counter", but
; rather place "counter" as an embedded non-linked table
; within a "customer" master form.
VIEW "counter"
COEDIT "customer"
;------start the wait interaction with user--------------------
WHILE true ; start a continuous loop
WAIT table
PROMPT "Press [F2] When done, Press [Ins] for a new Record",
""
UNTIL "F2", "Ins" ; Define other keys as you see fit.
; The system variable retval will be equal
; to the key you pressed.
SWITCH
CASE retval="F2" : DO_IT!
QUITLOOP ;this is only way out of loop
CASE retval="Ins" : END
DOWN ; in form view use CTRLPGDN
; opens a new record
[cust id]=COUNTER()
; place the result of the counter
; procedure into [cust id]
ENDSWITCH
ENDWHILE ;loop back to the WHILE command
CLEARALL CLEAR
;===============================================================