[thelist] generating an order #
Anthony Baratta
Anthony at Baratta.com
Tue Jan 7 01:24:00 CST 2003
At 11:02 PM 1/6/2003, Jeremy Weiss wrote:
>I'm writing some scripts to do online credit card processing. The processor
>requires that I pass them an order number along with everything else and I'm
>not quite sure how to go about creating an order number.
IMvHO - Order numbers need to be long enough to not repeat and but "look"
like order numbers. Here a bit of ASP I use to generate order numbers:
varOrderNumber = UniqueID_Time()
''''''''''''''''''''''''''
'' UniqueID_Time
''''''''''''''''''''''''''
Function UniqueID_Time()
Randomize Right(ABS(DateDiff("s",Now,#1/1/1998#)),4)
nBaseID = Right(Abs(DateDiff("s",Now,#1/1/1998#)),8)
UniqueID_Time = Right(Year(now),2) & Numeric_Pad(Month(now)) _
& "-" & Left(nBaseID,2) & "-" & Mid(nBaseID,3,3) _
& "-" & Right(nBaseID,3) & "-" & Int((998 - 101 + 1) * Rnd + 101)
End Function
''''''''''''''''''''''''''
'' Numeric_Pad
''''''''''''''''''''''''''
Function Numeric_Pad(varNumber)
if (Int(varNumber) < 10) then
varNumber = "0" & varNumber
end if
Numeric_Pad = varNumber
End Function
This could return an order number like this: 0301-58-246-279-369
The first 2 numbers are the "year", the next two are the month (so now the
order numbers are self sorting by calendar order date, and within months
are numerically sorted. Therefore all orders are in chronological order -
or should be ;-). The next three sets of numbers are based upon seconds
from 1998, and should not repeat for 3.2 years. Which should be long enough
to have separation between similar order numbers. Finally in order to help
against order numbers repeating in the off chance two or more people place
an order at the exact same second, a random 3 digit number is appended to
the mess.
Clear as mud?? Hope that helps.
---
Anthony Baratta
President
Keyboard Jockeys
"Conformity is the refuge of the unimaginative."
More information about the thelist
mailing list