"Why use an alphanumeric number rather than just a regular old number?" I asked. The requirement for an alphanumeric order number was written into an e-commerce spec on the project I was assigned to develop. The answer was a good one: volume. The Web site owners wanted to maintain a four-digit order number but didn't want to be limited to 10,000 orders (0000-9999). They were being optimistic about the store's volume.
So I did the math. The common numbering system is base 10, meaning that any single digit could be 0 through 9, so a four-digit number is 10 to the 4th power or 10,000 (0 through 9999). An alphanumeric number of the same length--four digits--would be base 36, or A through Z plus 0 through 9. So an alphanumeric four-digit number has 1.67 million possible order numbers.
There is, however, a potential problem with using an alphanumeric order number--namely, unintended spellings like "WE8U" (we hate you), "UASS," or the numerous other four letter words that would eventually show up. Use your imagination. The solution we settled on was to remove all vowels: a,e,i,o, and u. This had the added benefit of removing the possible confusion of the letter O with number 0.
For the example I'm showing here, I'm using a base 31, alphanumeric, four-digit number, which gives me 31 to the 4th power, or just under a million potential order numbers (923,521 to be exact).
I wrote it as a function in which you pass the "current" order number and get back the next order number in the sequence. You would still need to store your current "high" number somewhere.
function GetNextOrderNumber(Old_Number)
maxOrderID = Old_Number
Dim alphaNum
Dim alphaNumList
alphaNumList = "0,1,2,3,4,5,6,7,8,9,B,C,D,F,G,H,J,K,L,M,N,P,Q,R,S,T,V,W,X,Y,Z"
REM Note that the alphaNumList does not contain the vowels.
REM Split the alphanumList into an array
alphaNum = split(alphaNumList,",")
REM Parse the current order number into an array.
Dim F(4)
F(0) = Right(Left(maxOrderID,1),1)
F(1) = Right(Left(maxOrderID,2),1)
F(2) = Right(Left(maxOrderID,3),1)
F(3) = Right(Left(maxOrderID,4),1)
REM Loop thru each position starting with the last digit.
For Y = 3 to 0 Step -1
REM If the last position is Z then roll it over to 0
If F(Y) = "Z" then
F(Y) = "0"
else
For X = 0 to 30
If F(Y) = alphaNum(X) then
NewF = alphaNum(X+1)
End If
Next
F(Y) = NewF
exit for
End if
Next
REM Rebuild the new order number from the array
newOrderID = F(0) & F(1) & F(2) & F(3)
REM Return the new order number
GetNextOrderNumber = newOrderID
end function
That's it--a simple function to convert a four-digit number from 10,000 order numbers to just under 1 million potential order numbers. By the same logic, a six-digit number will give you 887 million potential order numbers. If we get 887 million orders in our store, I'm demanding a percentage and retiring.
Good luck and good coding.
--Robin G. Grimes
LATEST COMMENTS
MC Press Online