Hi,
Does anyone know GUID? I don't know what it
all about. can it be done in VB. I only know
that it can help generate unique number. Does anyone
have the code. Please help me! Thank You!
Printable View
Hi,
Does anyone know GUID? I don't know what it
all about. can it be done in VB. I only know
that it can help generate unique number. Does anyone
have the code. Please help me! Thank You!
Yeah thats really all it is , is an id so unique, chances of it being repeated ever is astronomical. Usuallly used to prevent dll conflicts. Here is code to generate one
Code:Private Declare Function CoCreateGuid Lib "OLE32.DLL" (pGuid As Guid) As Long
Private Declare Function StringFromGUID2 Lib "OLE32.DLL" (pGuid As Guid, ByVal lpStr As Long, ByVal MaxLength As Long) As Long
Private Const GUID_OK As Long = 0
Public Function GetNewGuid() As String
'*****************************************************************************
'* Purpose: This function is used to get a GUID for each Request.
'* Input: None
'* Output: Returns either a zero length string or a string containing a globally unique id key.
'*****************************************************************************
' Max length for buffer
Const GUID_LENGTH As Long = 38
Dim udtGUID As Guid
Dim sGUID As String
Dim ret As Long
' create the raw guid
ret = CoCreateGuid(udtGUID)
If ret = GUID_OK Then
' allocate space in string
sGUID = String$(GUID_LENGTH, 0)
' convert raw guid to a string
StringFromGUID2 udtGUID, StrPtr(sGUID), GUID_LENGTH + 1
Else
sGUID = ""
End If
GetNewGuid = sGUID
End Function
Is there any bugs in the code? Once again,
a million thank to you
regards
No bugs, This code has been used for 2 years in a web application I wrote and this function gets called over 70,000 times a year and has YET to make a duplicate guid number!
I'm getting a compile error - user defined type not defined -Quote:
Originally posted by Cander
No bugs, This code has been used for 2 years in a web application I wrote and this function gets called over 70,000 times a year and has YET to make a duplicate guid number!
what dumb thing am I doing?