|
同步复制ID,即GUID(全球同步唯一标识符),通过特定的算法,生成的一个128位的字符串,在纳秒级的时间内,任意两台电脑生成的GUID都不会相同(理论上在公元3400年以前如此),从而确保标识的唯一性。
- 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
- '生成GUID(同步复制ID) ===红尘如烟=======
- Public Function GetGUID() As String
- Dim typGUID As GUID
- If (CoCreateGuid(typGUID) = 0) Then
- GetGUID = GetGUID & String(8 - Len(Hex$(typGUID.Data1)), "0") & Hex$(typGUID.Data1) & "-"
- GetGUID = GetGUID & String(4 - Len(Hex$(typGUID.Data2)), "0") & Hex$(typGUID.Data2) & "-"
- GetGUID = GetGUID & String(4 - Len(Hex$(typGUID.Data3)), "0") & Hex$(typGUID.Data3) & "-"
- GetGUID = GetGUID & IIf((typGUID.Data4(0) < &H10), "0", "") & Hex$(typGUID.Data4(0))
- GetGUID = GetGUID & IIf((typGUID.Data4(1) < &H10), "0", "") & Hex$(typGUID.Data4(1)) & "-"
- GetGUID = GetGUID & IIf((typGUID.Data4(2) < &H10), "0", "") & Hex$(typGUID.Data4(2))
- GetGUID = GetGUID & IIf((typGUID.Data4(3) < &H10), "0", "") & Hex$(typGUID.Data4(3))
- GetGUID = GetGUID & IIf((typGUID.Data4(4) < &H10), "0", "") & Hex$(typGUID.Data4(4))
- GetGUID = GetGUID & IIf((typGUID.Data4(5) < &H10), "0", "") & Hex$(typGUID.Data4(5))
- GetGUID = GetGUID & IIf((typGUID.Data4(6) < &H10), "0", "") & Hex$(typGUID.Data4(6))
- GetGUID = GetGUID & IIf((typGUID.Data4(7) < &H10), "0", "") & Hex$(typGUID.Data4(7))
- End If
- End Function
复制代码
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|