Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Incrementing Alphabet
Message
From
25/04/1998 12:28:28
 
 
To
25/04/1998 12:24:07
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00094857
Message ID:
00094894
Views:
28
>>Today's Quiz. I want to maximize the number of choices I can assign to a group of records so I choose to use the alphabet through a three character field. How do I programatically increment the next assigned alphabetic character (i.e. AAA, AAB, AAC. .. AAZ then ABA, ABB, etc.)
>>
>>do I do this with ascii character (chr()) assignments or is there an easier way?
>>
>>Thanks in advance,
>>
>>Bill
>
>Suppose you have sort it in order, that means lastkey is largest!
>
>
>lcSelect = Select()
>Select MyTable
>Go Bottom
>lcLastKey = Alltrim(MyTable.MyKey)  && e.g. [BFZZ] -> [BFZ'A] --> [BGAA]
>NextKey = CalNextKey(lcLastKey)
>
>
>* CalNextKey.prg or Function CalNextKey
>Lparameter lcLastKey
>For iX = Len(lcLastKey) to 2 Step -1 && will problem if [ZZZ]
>If SubStr(lcLastKey, iX, 1) = [Z] && From Right to Left
>  * up the lcLastKey Till non-Z is found!
>  lcLastKey = left(lcLastKey, iX-2) + chr(asc(Substr(lcLastKey, iX-1,1))+1) + [A] + SubStr(lcLastKey, iX+1)
>Else
>  * normal case
>  lcNewKey = left(lcLastKey, iX-1) + chr(asc(Substr(lcLastKey, iX,1))+1) + ;
>             Substr(lcLastKey, iX+1)
>  Exit  && leave loop
>Endif
>EndFor
>
>If Left(lcNewKey, 1) > [Z]  && Independent of Hardware Platform
>  messagebox('OverFlow Error!!',16,'Calculate Next ID')
>  Return .F.
>else
>  Return lcNewKey
>ENDIF
>
>NOTE this is sth like calculation Sum with Logic Gate!
>
>
>Just Type the code, pls test if any error.
Oh Find error on adding tail. Sorry! ~~'.'~~
The weak wait for chance, The strong bid for chance,
The clever notch up chance, but The merciful give you chance.
Previous
Reply
Map
View

Click here to load this message in the networking platform