Category : Paradox DBMS
Archive   : AUTOINCR.ZIP
Filename : AUTOINCR.SC

 
Output of file : AUTOINCR.SC contained in archive : AUTOINCR.ZIP
; This script uses a combination of the WAIT command and the CMAX function
; to increment the Cust ID field of the Customer table.

; The table used in this example is from the SAMPLE directory which is
; part of the OPTIONAL installation within Paradox versions 3.xx.

; Note: this will not work in DATA ENTRY mode in Paradox because
; you are actually in a tempory table named "ENTRY" during
; DATA ENTRY mode. COEDIT mode is preferred.

; Note: This may not be appropriate in a multiuser environment
; since CMAX places locks on the table.

;-----------------------------------------------------------------------
;-----define the autoincrement procedure, should use with coedit mode---
proc autoincrement(tbl,fld)
if isblank([cust id]) then
[cust id]=cmax(tbl,fld)+1
endif
endproc
;-----------main body of script-----------------------------------

COEDIT "customer" ; coedit is better than edit since it updates
; the indexes as you go versus after a DO-IT!
;------------assign variables--------------------------------------
tbl="customer"
fld="cust id"
;------------start 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" : autoincrement(tbl,fld)
DO_IT!
QUITLOOP

CASE retval="Ins" : END
DOWN
INS ;open new record
autoincrement(tbl,fld)
;alternatively you could use COUNTER() from the code example below

ENDSWITCH
ENDWHILE ;loop back to the WHILE command

CLEARALL
CLEAR

;-------NOTE: In multiuser environment you may consider the following

;Contents : procedure counter
;Borrowed from the Paradox Developers Toolkit

;Special Notes : This procedure is very useful for entering a new invoice
; number for every new record entered into, for instance, an
; "Orders" table. Because Paradox doesn't have its own auto-
; incrementing feature, this procedure does the "trick" for
; you. You will need a one record one field table such as:
;
; Counter ÍËÍ Counter Í»
; º 10001 º
;
; You will also need to set up a special key. Upon
; pressing the special key, the value 10001 is tranfered
; to your "Orders" table and the value 10001 is changed to
; 10002 for the next time you get a new invoice number. This
; whole procedure can be entirely automated with the use of
; the Data Entry Toolkit and an arrival procedure.

;-----define the procedure COUNTER ----------------------------

PROC counter()
PRIVATE counter
UPIMAGE
lockrecord
counter = [Counter] ; You should use MOVETO "counter"
[Counter] = [Counter] + 1 ; if you have more than 2 tables on the workspace
unlockrecord
DOWNIMAGE ; AND, use LOCKRECORD in multiuser environment
RETURN counter
ENDPROC

;------ set up the workspace with counter and customer tables
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" : [cust id]=COUNTER() ;COUNTER returns new value
DO_IT!
QUITLOOP ;this is only way out of loop

CASE retval="Ins" : END
DOWN
INS ;open new record
[cust id]=COUNTER()
ENDSWITCH
ENDWHILE ;loop back to the WHILE command

CLEARALL CLEAR


  3 Responses to “Category : Paradox DBMS
Archive   : AUTOINCR.ZIP
Filename : AUTOINCR.SC

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/