Search Tools Links Login

create GUID

This program creates a GUID, a unique 128-bit integer used for CLSIDs and interface identifiers.The idea of a GUID is that no two machines can ever generate the same GUID value twice. This is achieved by using a combination of the current time, your machine's Media Access Control (MAC) address (a unique number built into all network cards) if it has one, and other routines.

Original Author: Ruchika

API Declarations

Private Declare Function CoCreateGuid Lib "ole32" (id As Any) As Long


Private Sub Form_Load()
  MsgBox "Generated GUID: " + CreateGUID
End Sub
Public Function CreateGUID() As String
  Dim id(0 To 15) As Byte
  Dim Cnt As Long, GUID As String
  If CoCreateGuid(id(0)) = 0 Then
    For Cnt = 0 To 15
      CreateGUID = CreateGUID + IIf(id(Cnt) < 16, "0", "") + Hex$(id(Cnt))
    Next Cnt
    CreateGUID = Left$(CreateGUID, 8) + "-" + Mid$(CreateGUID, 9, 4) + "-" + Mid$(CreateGUID, 13, 4) + "-" + Mid$(CreateGUID, 17, 4) + "-" + Right$(CreateGUID, 12)
    MsgBox "Error while creating GUID!"
  End If
End Function

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 76 times


Visual Basic 6


No attachments for this post

Loading Comments ...


No comments have been added for this post.

You must be logged in to make a comment.