This one does all I want. No need to use PADR() anymore. Very nice. The maximum number it supports is 456975. Thanks Sergey.
>Yes, I see the problem. Try (works even for 0)
>
> lcLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
> lcCharList = lcLetters
> lnBase = LEN(lcCharList)
> lcVal = ""
> FOR i=1 TO 4
> lnRest = (lnVal % lnBase)
> lnVal = INT( lnVal / lnBase)
> lcVal = SUBSTR( lcCharList, lnRest + 1 , 1 ) + lcVal
> ENDFOR
>
>
>>Nice shot. However, exactly your case ("whatever") showed a problem. It could be repaired by decreasing lnBase with 1 and increasing lnRest with 1. Here's the testcode:
>>
>>
create cursor c_sys2007 ( theNumber i, theString c(10) )
>>for n = 1 to 99999
>> lnval = n
>> lcLetters = "ABCDEFGHIJKLMNOPQRSTUVWXY"
>> lcCharList = lcLetters + LOWER(lcLetters)
>> lnBase = LEN(lcCharList) - 1
>> lcVal = ""
>> DO WHILE lnVal > 0
>> lnRest = lnVal % lnBase
>> lnVal = INT( lnVal / lnBase)
>> lcVal = SUBSTR( lcCharList, lnRest + 1, 1 ) + lcVal
>> ENDDO
>> insert into c_sys2007 values ( n, lcVal )
>>next
>>
>>browse title "Raw result"
>>
>>select cnt(*) as _cnt, theString from c_sys2007 order by 2 group by 2 into cursor c_sys2007a
>>browse title "Occurence of each string - Desc - Column 1 should have no other value than 1"
>>
>>select len(alltrim(thestring)) as theLen from c_sys2007a order by 1 desc into cursor c_sys2007b
>>select dist theLen from c_sys2007b order by 1 desc into cursor c_sys2007c
>>browse title "Distinct of lengths"
>>
>>I think I'll gonna use a variation. lcCharlist will be lcLetters only, in order to have only upper case in the outcome. And I want the string to be four positions always. That can be accomplished by reserving the Z, so by decreasing lcLetters with 1 and doing padr() with the Z.
>>
>>Problem solved. Thanks Sergey. Did you write this today?
>>
Groet,
Peter de Valença
Constructive frustration is the breeding ground of genius.
If there’s no willingness to moderate for the sake of good debate, then I have no willingness to debate at all.
Let's develop superb standards that will end the holy wars.
"There are three types of people: Alphas and Betas", said the beta decisively.
If you find this message rude or offensive or stupid, please take a step away from the keyboard and try to think calmly about an eventual a possible alternative explanation of my message.