Quantcast
Channel: West Wind Message Board Messages
Viewing all articles
Browse latest Browse all 10393

Re: INT to base 31 and back

$
0
0
Re: INT to base 31 and back
FoxPro Programming
Re: INT to base 31 and back
08/06/2012
04:24:35 PM
3KF0Z6B9W Show this entire thread in new window
Gratar Image based on email address
From:
Michael Hogan
To:
Attachments:
None
I've got the Code to Integer portion of the problem, I think:

************************************************************************ FUNCTION SKUToInt * Convert integer to SKU * SKUtoInt(SKU) in the form of "123ABC" ************************************************************************ PARAMETERS lcEncSKU PRIVATE aEncTab, lcEncSKU lcEncSKU = LTRIM(lcEncSKU,1,"0") aEncTab = [0123456789ABCDEFGHJKLQRSTUVWXYZ] && Exclude letters OIMNP, pad with zeros lnInt = 0 lnFactor = 1 *!* IF LEN(lcEncSKU) > 1 *!* SET STEP ON *!* ENDIF FOR i = LEN(lcEncSKU) TO 1 STEP -1 lcChar = SUBSTR(lcEncSKU,i,1) lnInt = lnInt + ((AT(lcChar,aEncTab)-1) * lnFactor) lnFactor = lnFactor*LEN(aEncTab) NEXT RETURN lnInt ENDFUNC && SKUToInt

Now I just need the integer to SKU (alphanumeric code) part...


I'm needing to convert to and from an INT value to a mix of characters [0123456789ABCDEFGHJKLQRSTUVWXYZ] (note that a few letters are missing to prevent confusion - oh and I, for example).

I'm thinking I just want to do some form of Base31 conversion (there are a total of 31 characters) but I cannot find an easy way of doing this in VFP. I suppose I could use AT() to assign a value to each character but at that point I'm into unfamiliar mathematics.

Has anyone already tackled this kind of problem?



Viewing all articles
Browse latest Browse all 10393

Trending Articles