Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Auto-increment with letters
Message
From
16/06/1998 09:50:01
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00108240
Message ID:
00108634
Views:
41
>I have made auto-incrementing keyfields before, using the system in TASTRADE. What would be a good system for auto-incrementing while having each "digit" cycle through a-z, or maybe 0-9 and a-z, or maybe A-Z and then a-z? Doing this would increase the number of available values. It would be useful to me because I have a legacy app, written using data from other people's legacy apps, which has a meaningful keyfield which is only five characters long, and always starts with a digit. Now they want to allow blank values in this field, and we don't feel like rewriting the whole thing. I propose to generate values always starting with a letter, which would appear as blank in reports.

I use this for some types of codes, where the number should be AAA-nnn, where AAA is a three-letter code based on date, and nnn is the daily counter. Gives some kind of a meaningful unique key:

*+ date to three char
* returns date packed into three characters (A-Z)
* v1.0 21.3.98 WMW Bar, for the bill serial number
* v1.1 14.6.98 additional parameter _len - 4 covers 26**4 dates;
giving 1251 years, 3 covers 48 (1990-2038)
*-
para _d, _du
if empty(_d)
_d=date()
endif
if empty(_du)
_du=3
endif
numdat=_d-{01.01.1990}
sl=""
for i=1 to _du
ns=numdat%26
sl=chr(ns+65)+sl
numdat=int(numdat/26)
endf
retu sl

You could simply start passing the number instead of date, adding more characters than I use here etc, but the principle would be the same.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Previous
Reply
Map
View

Click here to load this message in the networking platform