Results 1 to 15 of 15

Thread: VB6 - Random GUID Generator

Threaded View

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Oct 2008
    Posts
    1,238

    VB6 - Random GUID Generator

    It makes type 4 GUID (fully random) rather that type 1 (time based) or type 2 (network hardware based).

    Filename is: GUIDgenerator.bas

    Source is:
    Code:
    Attribute VB_Name = "GUIDgenerator"
    Private MyGUID(35) As Byte
    Private DashNum As Byte
    Private FourNum As Byte
    
    Public Sub GenInit()
    Randomize
    FourNum = Asc("4")
    DashNum = Asc("-")
    End Sub
    
    Public Function GenGUID() As String
    For i = 0 To 7
    MyGUID(i) = Asc(Hex(Int(16 * Rnd())))
    Next i
    
    For i = 9 To 12
    MyGUID(i) = Asc(Hex(Int(16 * Rnd())))
    Next i
    
    For i = 15 To 17
    MyGUID(i) = Asc(Hex(Int(16 * Rnd())))
    Next i
    
    For i = 19 To 22
    MyGUID(i) = Asc(Hex(Int(16 * Rnd())))
    Next i
    
    For i = 24 To 35
    MyGUID(i) = Asc(Hex(Int(16 * Rnd())))
    Next i
    
    MyGUID(8) = DashNum
    MyGUID(13) = DashNum
    MyGUID(14) = FourNum
    MyGUID(18) = DashNum
    MyGUID(23) = DashNum
    
    GenGUID = "{" & StrConv(MyGUID, vbUnicode) & "}"
    End Function

    Copy this code and paste it into a text file, save it, and rename it GUIDgenerator.bas
    and you can start implementing GUIDs in your VB6 programs.
    Last edited by Ben321; Nov 23rd, 2009 at 12:48 AM.

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