Results 1 to 4 of 4

Thread: STRING to GUID

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Posts
    69

    Angry STRING to GUID

    Ok I've been trying and trying but can't figure it out.

    I have a SQL 6.5 database that I need to run SQL statements searching a binary field which contains GUIDs. Now, before I run the query I have the string value of the GUID, for example "BC713507-8AB8-11D2-B4A9-0008C7FA5601".

    Obviously I can't use that and get results so I need to convert it to the binary value first but I don't know how to in VB6.

    If only this were SQL 7 then I could do it easily.

    Please help!

  2. #2
    Addicted Member
    Join Date
    Feb 2003
    Posts
    237
    VB Code:
    1. Private Type guid
    2.     Data1 As Long
    3.     Data2 As Integer
    4.     Data3 As Integer
    5.     Data4(7) As Byte
    6. End Type
    7.  
    8. Private Declare Function CLSIDFromString Lib "ole32.dll" (ByVal pstCLS As Long, clsid As guid) As Long
    9.  
    10. Private Sub form_load()
    11.     Dim s As String
    12.     Dim x, i
    13.     Dim g As guid
    14.    
    15.     s = "{BC713507-8AB8-11D2-B4A9-0008C7FA5601}"
    16.    
    17.     CLSIDFromString StrPtr(s), g
    18.    
    19.     For i = 0 To UBound(g.Data4)
    20.         x = x & Hex(g.Data4(i)) & " "
    21.     Next
    22.    
    23.     Debug.Print Hex(g.Data1) & " " & Hex(g.Data2) & Hex(g.Data3) & x

    if that isnt the right format for the fields you can
    also get it as a byte array but looks byteswapped in kind
    of weird way

    VB Code:
    1. Private Declare Function CLSIDFromString Lib "ole32.dll" (ByVal lpszProgID As Long, pCLSID As Any) As Long
    2.  
    3. Dim guid(15) As Byte
    4.  
    5.     ' convert from string to a binary CLSID
    6.     CLSIDFromString StrPtr(s), guid(0)
    7.     For i = 0 To UBound(guid)
    8.         x = x & Hex(guid(i)) & " "
    9.     Next
    10.     Debug.Print x


    when in doubt..news groups are your friend

    http://groups.google.com/groups?as_q...&num=100&hl=en
    Free Code, papers, tools, and more

    http://sandsprite.com

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Posts
    69
    That is close, but the result I need is

    73571BCB88AD211B4A90008C7FA5601

    with using the byte array example I am getting

    73571BCB88AD211B4A908C7FA561

    It is missing 3 zeros...

  4. #4

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Posts
    69
    NM that, I figured it out.

    Thanks!

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