Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Proceedure Code for Primary Key
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00168028
Message ID:
00168086
Views:
24
>Here's my Getkey() program:
>
>
>PARAMETER lcKeyName
>
>LOCAL lnKeyNum
>
>IF NOT USED("keylist")
>   USE keylist IN 0
>ENDIF
>IF SEEK(ALLTRIM(lcKeyName),"keylist","idxKname")
>   REPLACE keynum WITH keynum+1 IN "keylist"
>   lnKeyNum = keylist.keynum
>ELSE
>   lnKeyNum = 0
>ENDIF
>USE IN keylist
>RETURN lnKeyNum
>
There's a bit of error-checking you can add to this routine.
PARAMETER lcKeyName

LOCAL lnKeyNum

IF NOT USED("keylist")
   USE keylist IN 0
ENDIF

lnKeyNum = 0

IF SEEK(ALLTRIM(lcKeyName),"keylist","idxKname")
   IF RLOCK()    && You don't want two users getting the
                 && same number....
      REPLACE keynum WITH keynum+1 IN "keylist"
      lnKeyNum = keylist.keynum
      UNLOCK
   ENDif
ENDIF
*USE IN keylist    && You will only do this until the
                   && first time you do a large APPEND FROM
                   && into this table. :-)
RETURN lnKeyNum
Now that I think about it, it might be better to set lnKeyNum to .NULL., rather than 0: it's a better out-of-bounds indicator.
My blog
My consulting page
My home page

Member of the Trim Your Auto-Quote Campaign!
What's another word for thesaurus?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform