I GOT IT!! yea!
I just changed it as follows...
FOR ....
nDividend = IIF( X > 0, nDividend - (X*(nBase^j)), nDividend)
ENDFOR
Thanks for the input.
Rick
---------------
>David,
>
>I've put together a routine, based on one that John Koziol attempted in message 139988.....
>
>*** Convert From Some Base (2-36) to Decimal (Base-10)
>PROCEDURE BaseToDecimal
>LPARAMETERS nBase, cBaseValue
>LOCAL nDecValue,i, BaseString
>nDecValue=0
>BaseString = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
>
>FOR i = 1 TO LEN(cBaseValue)
> nDecValue=nDecValue+((AT(SUBSTR(cBaseValue,i,1),BaseString)-1)*nBase^(LEN(cBaseValue)-i))
>ENDFOR
>RETURN nDecValue
>
>
>But it goes in the opposite direction of what I want. I'm working on another routine....
>
>*** Convert From Some Base (2-36) to Decimal (Base-10)
>PROCEDURE DecimalToBase
>LPARAMETERS nBase, nDecValue
>LOCAL cBaseValue, i, j, X, BaseString, nRemainder, nDividend
>cBaseValue = ""
>i = 0
>j = 0
>X = 0
>BaseString = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
>nRemainder = nDecValue
>nDividend = nDecValue
>
>DO WHILE nBase^i < nDecValue
> i = i + 1
>ENDDO
>
>FOR j = i to 1 STEP -1
> X = INT(nDividend/(nBase^j))
> nRemainder = MOD(nDividend, nBase) && or I could have said (nDividend % nBase)
> cBaseValue = cBaseValue + substr( BaseString, X+1, 1)
> nDividend = nRemainder && this line is wrong
>ENDFOR
>cBaseValue = cBaseValue + substr( BaseString, nRemainder+1, 1)
>RETURN cBaseValue
>
>But this isn't working yet...
>I know this has been done before...I hate reinventing the wheel!!!
>
>-------------------
>>David,
>>I need a base-36 number because it is used by an outside vendor as their unique identifier, and when I send my file to them it has to have this number.
>>---------------
>>>Rick,
>>>
>>>Why not just more simply use an integer field?
>>>-----------
>>>>I'm looking for a routine to convert a base-10 number to a base-36 number (0-9,A-Z). I need to create an incrementing counter in Base-36...or increment in base-10 and convert to base-36.
Previous
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only