Results 1 to 6 of 6

Thread: Unique numbers

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Location
    Melbourne, Australia
    Posts
    3
    Will somebody please help a newbie create unique numbers in VB6, hopefully using DateTime stripped of non-numeric characters?
    Any help gratefully accepted.

    Patrick
    VB6 Ent SP3
    (tis better to light a candle than rail against the darkness)

  2. #2
    Guest
    Do you mean stripping a Date-Time Var clean of non-num chars?

    Code:
    Function Strip(DateTime as Date) As Long
        Dim s, i, t, ss
        s = Str(DateTime)
        For i = 1 To Len(s)
            t = Mid(s, i, 1)
            If Not IsNumeric(t) then t = ""
            ss = ss + t
        Next
        Strip = Int(ss)
    End Function

  3. #3
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620
    Or to create random(unique) numbers:
    Code:
    Text1.Text = Int(Rnd * 1000)
    Gl,
    D!m
    Dim

  4. #4
    Guest
    Try this code: It creates a GLOBAL UNIQUE IDENTIFIER (which should be always unique ... in the world(!) )...

    Create a new project and add a command-button and a Label

    Paste this code

    Code:
    Option Explicit
    
    Private Type GUIDType
        D1       As Long
        D2       As Integer
        D3       As Integer
        D4(8)    As Byte
    End Type
    
    Private Declare Function WinCoCreateGuid Lib "OLE32.DLL" Alias "CoCreateGuid" (g As GUIDType) As Long
    
    Public Function CreateGUIDString() As String
        Dim g As GUIDType
        Dim sBuf As String
        Call WinCoCreateGuid(g)
        
        sBuf = _
            PadZeros(Hex$(g.D1), 8, True) & _
            PadZeros(Hex$(g.D2), 4, True) & _
            PadZeros(Hex$(g.D3), 4, True) & _
            PadZeros(Hex$(g.D4(0)), 2) & _
            PadZeros(Hex$(g.D4(1)), 2, True) & _
            PadZeros(Hex$(g.D4(2)), 2) & _
            PadZeros(Hex$(g.D4(3)), 2) & _
            PadZeros(Hex$(g.D4(4)), 2) & _
            PadZeros(Hex$(g.D4(5)), 2) & _
            PadZeros(Hex$(g.D4(6)), 2) & _
            PadZeros(Hex$(g.D4(7)), 2)
        CreateGUIDString = sBuf
    End Function
    
    Private Function PadZeros(ByVal sBit As String, ByVal iStrLen As Integer, Optional bHyphen As Boolean) As String
        If iStrLen > Len(sBit) Then
            sBit = Right$(String$((iStrLen - Len(sBit)), "0") & sBit, iStrLen)
        End If
        If bHyphen Then sBit = sBit & "-"
        PadZeros = sBit
    End Function
    
    Private Sub Command1_Click()
        Label1.Caption = CreateGUIDString
    End Sub
    Enjoy!

  5. #5
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    For trouble ticket systems I wrote in ASP once upon a time I used

    round(Cdbl(NOW()) * 100000,0)

    so you could trace the ticket back to the time it was created.

    or if user load is high then multiply by 10,000,000 so you get 1000 per second rather than 10

    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  6. #6
    Guest
    Guys.

    He told me, by e-mail, that he had already solved the problem. He does mean what I thought, and He used Format(now, "MMddyyhhmmss") and solved it. We should stop trying to overcrowd VB-World [JOKE].

    He solved it, so it saves energy to stop.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width