Predmet:Re: Access trikovi
Kreiranje GUIID
Ako nekome treba GUIID za slanje podataka
PreuzmiIzvorni kôd (Visual Basic):Option Explicit
DefLng A-Z
Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As String * 1
End Type
Declare Function CoCreateGuid Lib "ole32.dll" (tGUIDStructure As GUID) As Long
'Za access 64 bita
' Declare PtrSafe Function CoCreateGuid Lib "ole32.dll" (tGUIDStructure As GUID) As Long
Const mciLen As Integer = 4 'svakih part's
Public Function CreateGUID() As String
Dim sGUID As String '= result
Dim TGUID As GUID 'unutar structure
If CoCreateGuid(TGUID) = 0 Then ' API uzmi GUID
With TGUID 'build return string
sGUID = "{" & PadLeft(Hex(.Data1), mciLen * 2) & "-"
sGUID = sGUID & PadLeft(Hex(.Data2), mciLen) & "-"
sGUID = sGUID & PadLeft(Hex(.Data3), mciLen) & "-"
sGUID = sGUID & FormatGUIDData4(.Data4())
End With
sGUID = sGUID & "}" 'end
CreateGUID = sGUID
End If
End Function
Private Function FormatGUIDData4(aryData4() As String * 1) As String
Dim i As Integer 'loop KROZ
Dim sGUID As String 'resultat
Dim sTemp1 As String '1. part
Dim sTemp2 As String '2.part
For i = LBound(aryData4()) To UBound(aryData4()) 'process string array
If i < 2 Then '1. part
sTemp1 = sTemp1 & Hex(Asc(aryData4(i)))
Else '2. part
sTemp2 = sTemp2 & Hex(Asc(aryData4(i)))
End If
Next
sGUID = PadLeft(sTemp1, mciLen) & "-" & PadLeft(sTemp2, mciLen * 3) 'pad left s nulama
FormatGUIDData4 = sGUID 'return gotov
End Function
Private Function PadLeft(sString As String, iLen As Integer) As String
' left zreos ako bude
Dim sTemp As String
sTemp = right$(String$(iLen, "0") & sString, iLen)
PadLeft = sTemp
End Function