Question : How to customize a GUID creation function

I need to create a customized GUID to be able to export my data to another system.  I found a great function that creates one, but I can't figure out how to customize it to insert some hyphens where I need them.  Can you?  

The code comes from the microsoft kb, http://support.microsoft.com/kb/176790 & I attached it below.  The format I need for the GUID needs 4 hyphens at positions 9, 14, 19, & 24, e.g., 7BD78946-7813-28B4-F8FE-2736DA2929CA.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(7) As Byte
End Type
 
Private Declare Function CoCreateGuid Lib "OLE32.DLL" (pGuid As GUID) As
Long
 
Public Function GetGUID() As String
'(c) 2000 Gus Molina
 
Dim udtGUID As GUID
 
If (CoCreateGuid(udtGUID) = 0) Then
 
GetGUID = _
String(8 - Len(Hex$(udtGUID.Data1)), "0") & Hex$(udtGUID.Data1) & _
String(4 - Len(Hex$(udtGUID.Data2)), "0") & Hex$(udtGUID.Data2) & _
String(4 - Len(Hex$(udtGUID.Data3)), "0") & Hex$(udtGUID.Data3) & _
IIf((udtGUID.Data4(0) < &H10), "0", "") & Hex$(udtGUID.Data4(0)) & _
IIf((udtGUID.Data4(1) < &H10), "0", "") & Hex$(udtGUID.Data4(1)) & _
IIf((udtGUID.Data4(2) < &H10), "0", "") & Hex$(udtGUID.Data4(2)) & _
IIf((udtGUID.Data4(3) < &H10), "0", "") & Hex$(udtGUID.Data4(3)) & _
IIf((udtGUID.Data4(4) < &H10), "0", "") & Hex$(udtGUID.Data4(4)) & _
IIf((udtGUID.Data4(5) < &H10), "0", "") & Hex$(udtGUID.Data4(5)) & _
IIf((udtGUID.Data4(6) < &H10), "0", "") & Hex$(udtGUID.Data4(6)) & _
IIf((udtGUID.Data4(7) < &H10), "0", "") & Hex$(udtGUID.Data4(7))
End If
 
End Function

Answer : How to customize a GUID creation function

Public Function GetGUID() As String
'(c) 2000 Gus Molina
 
Dim udtGUID As GUID
Dim sGUID As String

If (CoCreateGuid(udtGUID) = 0) Then
 'The format I need for the GUID needs 4 hyphens at positions 9, 14, 19, & 24,
 'e.g., 7BD78946-7813-28B4-F8FE-2736DA2929CA.
sGUID = _
String(8 - Len(Hex$(udtGUID.Data1)), "0") & Hex$(udtGUID.Data1) & _
String(4 - Len(Hex$(udtGUID.Data2)), "0") & Hex$(udtGUID.Data2) & _
String(4 - Len(Hex$(udtGUID.Data3)), "0") & Hex$(udtGUID.Data3) & _
IIf((udtGUID.Data4(0) < &H10), "0", "") & Hex$(udtGUID.Data4(0)) & _
IIf((udtGUID.Data4(1) < &H10), "0", "") & Hex$(udtGUID.Data4(1)) & _
IIf((udtGUID.Data4(2) < &H10), "0", "") & Hex$(udtGUID.Data4(2)) & _
IIf((udtGUID.Data4(3) < &H10), "0", "") & Hex$(udtGUID.Data4(3)) & _
IIf((udtGUID.Data4(4) < &H10), "0", "") & Hex$(udtGUID.Data4(4)) & _
IIf((udtGUID.Data4(5) < &H10), "0", "") & Hex$(udtGUID.Data4(5)) & _
IIf((udtGUID.Data4(6) < &H10), "0", "") & Hex$(udtGUID.Data4(6)) & _
IIf((udtGUID.Data4(7) < &H10), "0", "") & Hex$(udtGUID.Data4(7))

sGUID = Mid(sGUID, 1, 8) & "-" & Mid(sGUID, 9, 4) & "-" & Mid(sGUID, 13, 4) & "-" & Mid(sGUID, 17, 4) _
    & "-" & Mid(sGUID, 21, 12)
   
GetGUID = sGUID


End If
 
End Function
Random Solutions  
 
programming4us programming4us