VFP doesn't currently have this feature (although it was demonstrated as a possible new feature in Toledo - VFP 8.0!) See the sample code in Tastrade to for one implementation [ DO (_samples+"\tastrade\tastrade" ]. Or go to Craig's site (
If in multi-user scenario, you'll need to temporarily perform an RLOCK on the lookup table that holds the sequence counter to ensure that other users don't get the same number.
My adaptation:
FUNCTION NewKeyID
LPARAMETER tcAlias
* tcAlias is the name of the table which needs a unique key value
LOCAL lcAlias, lcID, lcOldReprocess, lnOldArea
lnOldArea = SELECT()
IF PARAMETERS() < 1 then
lcAlias = UPPER(ALIAS())
ELSE
lcAlias = UPPER(tcAlias)
ENDIF
*-- Lock until user presses Esc
SET REPROCESS TO AUTOMATIC
IF NOT USED("SETUP" then
USE lookupdb!setup IN 0 shared
endif
IF SEEK(lcAlias,"setup","keyname" then
IF RLOCK("setup" then && will wait for lock if necessary
lcID = setup.keyvalue
REPLACE keyvalue WITH (lcID + 1) IN SETUP
UNLOCK in "setup"
ENDIF
else
messagebox("Cannot find " + lcAlias + " in LOOKUPDB!SETUP table for unique key generation.",16,"Unique key generation problem."
ENDIF
SELECT (lnOldArea)
SET REPROCESS TO lcOldReprocess
RETURN lcID
ENDFUNC && NewKeyID
HTH,
--Michael
Michael J. Babcock, MCP
Founder, Central PA Visual Foxpro Users Group
mbabcock@cpvfug.org
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.