Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Incrementing Alphabet
Message
From
25/04/1998 19:36:14
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00094857
Message ID:
00094935
Views:
19
Bill,

The cool answer to your amiable quiz is below. The reason it's the cool answer is because what you want to do is just to count in Base 26 using the character set A-Z.

Adam



***************
Function Char26
***************
* Returns the base 26 value of a number from 0-25 in char set A-Z
* Adam Weisberg
Parameter pnNum10
pnNum10 = Int(pnNum10)
IF pnNum10 > 25
RETURN "*"
ENDIF
RETURN CHR(ASC("A")+pnNum10)

**************
Function Num26
**************
* Returns the base 26 value of a number in char set A-Z
* Adam Weisberg
Parameter pnNumTen
lnDigits = 1
lnMyNum = Int(pnNumTen)
lcRetVal = ''
DO WHILE lnMyNum/26^(lnDigits) >= 1
lnDigits = lnDigits + 1
ENDDO
FOR lnCount = lnDigits TO 1 STEP -1
lcRetVal = lcRetVal + Char26(Int(lnMyNum/26^(lnCount-1)))
lnMyNum = lnMyNum - 26^(lnCount-1)*Int(lnMyNum/26^(lnCount-1))
ENDFOR
RETURN lcRetVal
*****************

Function Num26() returns the base 26 equivalent of a number using the character set A-Z. You could modify it to include 0-9 without all that much trouble. Then it is counting in base 36. You'll get lots more out of your 3 characters that way. You can also turn a base 26 number in this format into a base 10 number for easy incrementing. I didn't provide the code, but you use a similar technique. Just write 2 functions, one that returns 0 for A and 25 for Z and the right stuff in between. It should take 1 or 2 lines for that. Then the other function cycles through the string XXX and increments a counter, multiplying the value of the letter times 26^decimal place (starting with 0).

Adam
Previous
Reply
Map
View

Click here to load this message in the networking platform