Results 1 to 5 of 5

Thread: Guid Help Needed. Thank You

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2001
    Posts
    89

    Angry

    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!

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    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
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2001
    Posts
    89

    Thank You Cander!

    Is there any bugs in the code? Once again,
    a million thank to you
    regards

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    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!
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  5. #5
    Fanatic Member Kzin's Avatar
    Join Date
    Dec 2000
    Posts
    611
    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
  •  



Click Here to Expand Forum to Full Width