Here's a solution; two functions FROMBASE and TOBASE - FROMBASE converts a string using the provided translator string as the base for the numbering system as a decimal number. TOBASE returns a string given a decimal number and translator string.
FUNCTION FROMBASE
lparameters cIncoming, cTranslateString
LOCAL nResult, nSizeOfBase, nPos, nOrigLen, nXlateDigit
nOrigLen = LEN(cIncoming)
nSizeOfBase = LEN(cTRanslateString)
nResult = 0
FOR nPos = 1 TO nOrigLen
nXlateDigit = AT(SUBST(cIncoming,nPos,1),cTranslateString)
nResult = nResult * nSizeOfBase + MAX(0,nXlateDigit-1)
ENDFOR
RETURN nResult
FUNCTION TOBASE
lparameters nConvertBack, cTranslateString
LOCAL cString, nBase, nRemainder, nWorkVal
nBase = LEN(cTranslateString)
nWorkVal = nConvertBack
cString = ''
DO WHILE nWorkVal > 0
nRemainder = MOD(nWorkVal,nBase)
cString = SUBST(cTranslateString,nRemainder + 1,1) + cString
nWorkVal = INT(nWorkVal/nBase)
ENDDO
RETURN cString
cXlate = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
cIncrementString = TOBASE(FROMBASE(cMyValue,cXlate)+1,cXlate)
You can use this to translate between numbers in different numbering systems:
cHexNumberSystem ='0123456789ABCDEF'
cBaseNineSystem = '012345678'
cBase9String = TOBASE(FROMBASE(cMyHexString,cHexNumberSystem),cBaseNineSystem)
hth,
Ed
>Michel, check out my reply to Fred.
>
>I am well on my way to creating 2 functions that will do what I need, and fairly efficiently, I think...
>
>>Erik,
>>
>>I do not think the logic should be too hairy.
>>
>>Create a function that takes a letter, increments it (after
>>converting it to a number), and returns two pieces of information,
>>the letter it has been incremented to, and zero or one. Zero
>>indicates that you do not need to anything more, 1 means you need
>>to increment the next letter.
>>
>>Then call this function for the first digit. Return of Zero, do nothing
>>with the other digits, return of 1, call the function with the next
>>digit to the left, etc...., to the end. (Moving from one digit to the next
>>digit to the left can be a FOR...NEXT loop).
>>
>>All of this can be in a wrapper function to which you pass your initial
>>string, eg.. (X = WRAPPER_FUNCTION("AABC"))
>>
>>I did that once but not in FoxPro, and it was relatively quick
>>to code.
>>
>>Hope it all made sense.
>>
>>Michel.
>>
>>PS: To return two pieces of information from a function, return them
>>as a string and split them out.
>>
>>=================== Original message follows ====================
>>
>>>>Do you have a copy of Codebook? I'm pretty sure there's a Base36 function in there that could be adapted to what you want.
>>>
>>>Yeah, I do. I have looked in the book, because I thought I remembered something like that, but I didn't find it. I also did a search of my codebook projects (using my nifty SearchString tool :-)) and came up with nothing. Do you remember what the function is called?
>>>
>>>
>>>>Otherwise just take the rightmost char, use asc() to convert it to a number, increment it, if goes over "Z" set it to A and increment the next digit to the left.
>>>
>>>I started laying out logic to do exactly this and it got pretty hairy. That's why I was looking for some other creatice solutions...
>>>
>>>Thanks for your help.