|
-
Mar 28th, 2001, 10:52 AM
#1
Thread Starter
Lively Member
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!
-
Mar 28th, 2001, 10:57 AM
#2
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
-
Mar 28th, 2001, 11:08 AM
#3
Thread Starter
Lively Member
Thank You Cander!
Is there any bugs in the code? Once again,
a million thank to you
regards
-
Mar 28th, 2001, 11:21 AM
#4
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!
-
Nov 13th, 2001, 12:30 PM
#5
Fanatic Member
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!
I'm getting a compile error - user defined type not defined -
what dumb thing am I doing?
 Looking for a friendly intelligent chat forum? Visit the white-hart.net 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|