Visual Basic 6 - Create a unique serial number from Date/Time that is 8 Characters long using numbers and letters.

Visual Basic 6 - I need to create a unique serial number from Date/Time that is 8 Characters long using numbers and letters.  So anyone that could write some code to show me how to do this would be greatly appreciated.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

if you are not paticular about the length (8 chars), you can generate GUID which will be unique.
Yes, an 8 character limit would be tricky. The code below will generate a unix timestamp which is 10 characters long, if that's any good.

'Used to get the UTC system time for the Unix Timestamp function
Private Declare Sub GetSystemTime Lib "kernel32.dll" (ByRef lpSystemTime As SYSTEMTIME)
   wYear         As Integer
   wMonth        As Integer
   wDayOfWeek    As Integer
   wDay          As Integer
   wHour         As Integer
   wMinute       As Integer
   wSecond       As Integer
   wMilliseconds As Integer
End Type
Private Function GetUnixTimeStamp(Optional ByVal dFrom As Date = 0) As Double
Dim dSysUTC As Date, sysTime As SYSTEMTIME
    If dFrom = 0 Then
        GetSystemTime sysTime
        With sysTime
            .wDay = Day(dFrom)
            .wHour = Hour(dFrom)
            .wMinute = Minute(dFrom)
            .wMonth = Month(dFrom)
            .wSecond = Second(dFrom)
            .wYear = Year(dFrom)
        End With
    End If
    dSysUTC = DateSerial(sysTime.wYear, sysTime.wMonth, sysTime.wDay) + _
                                                    TimeSerial(sysTime.wHour, sysTime.wMinute, sysTime.wSecond)
    GetUnixTimeStamp = DateDiff("s", #1/1/1970#, dSysUTC)
End Function

Open in new window

Well, for starters, you can encode the date with three characters.
Months = 1,2,3,4,5,6,7,8,9,A,B,C
Year=0,1,2,3,4,5,6,7,8,9,A,B,C...X,Y,Z, (continue with lower case or other characters) where 0 = 2000 (good until 2036 just using the letters A-Z).

That leaves 5 characters
Hours = 1,2,3...B,C

Four more to go...
The number of 1/10th of seconds since midnight can be encoded as a 3 digit Base36 number.  
VB can't get time much more accurate than that (as I believe the functions DATE and TIME return a double where the decimal indicates the time where 0.5 = noon, 0.75 = 6pm, and the resolution isn't any better than the OS clock ticks, which there are something like 16.4 (?) ticks per second.

That leaves one more digit that you can try to encode as a serial number.  Othere wise, you could use 4 digits in HEX to encode the #of 1/10th of seconds since midnight.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.