asp tutorials, asp.net tutorials, sample code, and Microsoft news from 15Seconds
Data Access  |   Troubleshooting  |   Security  |   Performance  |   ADSI  |   Upload  |   Email  |   Control Building  |   Component Building  |   Forms  |   XML  |   Web Services  |   ASP.NET  |   .NET Features  |   .NET 2.0  |   App Development  |   App Architecture  |   IIS  |   Wireless
 
Pioneering Active Server
 Power Search





Active News
15 Seconds Weekly Newsletter
• Complete Coverage
• Site Updates
• Upcoming Features

More Free Newsletters
Reference
News
Articles
Code Samples
Components
Tools
New
Free
Downloads
Vendors
FAQ
Feedback
Books
Links
DL Archives
Community
Messageboard
List Servers
Mailing List
WebHosts
Consultants
Tech Jobs
15 Seconds
Home
Site Map
Press
Legal
Privacy Policy
internet.commerce














internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

HardwareCentral
Compare products, prices, and stores at Hardware Central!

Incrementing an Alpha-Numeric Number

An alpha-numeric number is a number that contains both letters and numbers.
(Example: B2XC41YD)

Why use an alpha-numeric number rather than just a regular old number I asked? The requirement for an alpha-numeric order number was written into an eCommerce spec on the project I was assigned to develop. The answer was a good one...volume. The Web site owners wanted to maintain a 4-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 Base10, meaning that any single digit could be 0-9. So a 4 digit number is 10 to the 4th power or 10,000 (0 thru 9999). An alpha-numeric number of the same length, 4 digits, would be Base36 or A-Z plus 0-9. So an alpha-numeric 4-digit number has 1.67 million possible order numbers.

There is, however, a potential problem with using an alpha-numeric 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 zero 0.

So we will be using a Base31 alpha-numeric 4-digit number for this sample, which gives us 31 to the 4th power or just under 1 million potential order numbers (923,521 to be exact). Enough chatter, let's get into the code.

I wrote it as a function where 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.


REM Open the function and pass in the old number
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"

'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 4-digit number from 10,000 order numbers to just under 1 million potential order numbers. By the same logic a 6-digit number will give you 887 million potential order numbers. If we have 887 million orders in our store, I'm demanding a percentage and retiring. Good luck and good coding.

Robin G. Grimes is currently converting sites he developed for Compaq to the new Hewlett Packard design. His favorite project is an eCommerce site that sells Compaq Spare Parts (http://sparesstore.compaq.com/sparesstore).

Based in Houston Texas, he started in database development with Stewart Title and moved to Internet development while working for Williams Communications. His current field of expertise is ASP, VBScript and Webcrossing. Webcrossing is a commercial forums language used by Compaq, Apple, Adobe and many others. He is a frequent poster at www.webxharbor.com, where he enjoys solving problems helping others, and finding solutions to his own issues.

Robin can be reached at Robin@thegrimes.com, and welcomes all feedback on this article and related topics.



email this code sample to a colleague




Support the Active Server Industry

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs