GUID Generator
06.05.2015 12:57:34
Alex
ich habe eine Frage zur Erstellung von GUIDs. Habe auch was zusammengesucht und es funktioniert. Das Grundprinzip mit der API- Funktion ist mir klar aber die einzelnen Schritte nachzuvollziehen fällt mir schwer. Könnt ihr mir dabei helfen? Evt. die einzelnen Schritte zu kommentieren mit dem was sie tun?
Type GUID
data1 As Long
data2 As Integer
data3 As Integer
data4(7) As Byte
End Type
Declare Function CoCreateGuid Lib "OLE32.DLL" (pGuid As GUID) As Long
Public Function NewGUID() As String
Dim result As String
Dim uid As GUID
CoCreateGuid uid
result = hex0(uid.data1, 8) & "-" & _
hex0(uid.data2, 4) & "-" & _
hex0(uid.data3, 4) & "-" & _
hex0(uid.data4(0), 2) & hex0(uid.data4(1), 2) & "-"
Dim i As Integer
For i = 2 To 7
result = result & hex0(uid.data4(i), 2)
Next
NewGUID = result
End Function
Private Function hex0(n As Variant, digits As Integer) As String
Dim k As Integer
k = Len(Hex(n))
hex0 = String(digits - Len(Hex(n)), "0") & Hex(n)
End Function