Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Auto generate alphanumeric codes
Message
From
13/03/2000 23:46:06
 
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00345198
Message ID:
00345219
Views:
20
>I need to programmatically generate and incremented unique alpha-numeric codes 3 characters long. For example, 001,002,003...AAA,AAB,AAC etc. Is there an algorithm that can do this automatically?

If you set a string equal to the characters you want to use say 0-9 and A-Z, you could do this with base36 math.

"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"

so 0 would be "000", 1 would be "001", 10 would be "00A", 36 would be "010" and 25000 would be "JAG"
d1 = INT(numval/36*36) = 19           (20th character "J")
d2 = INT((numval-(d1*36*36))/36) = 10 (11th character "A")
d3 = MOD(numval,36) = 16              (17th character "G")
Fred
Microsoft Visual FoxPro MVP

foxcentral.net
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform