ใน mysql สามารถ ใช้ได้โดยตรง select guid()
ในภาษาอื่น ก็ มีฟังชั่นสำหรับสร้างขึ้นด้วยได้
Option Explicit
Type GUID
l1 As Long
l2 As Long
l3 As Long
l4 As Long
End Type
Declare Function CoCreateGuid Lib "ole32.dll" (lpGuid As GUID) As Long
Declare Function StringFromGUID2 Lib "ole32.dll" (lpGuid As GUID, ByVal lpString As String, ByVal cbBytes As Integer) As Integer
Public Function UniqueValue() As String
Dim id As GUID
Dim sTemp$
Dim nLen%, hr&
hr = CoCreateGuid(id)
If (hr = 0) Then
sTemp = StrConv(String(38, Chr(0)), vbUnicode)
nLen = StringFromGUID2(id, sTemp, Len(sTemp))
sTemp = StrConv(sTemp, vbFromUnicode)
If (nLen > 0) Then
If (Left(sTemp, 1) = "{") Then sTemp = Right(sTemp, Len(sTemp) - 1)
If (Right(sTemp, 1) = "}") Then sTemp = Left(sTemp, Len(sTemp) - 1)
nLen = InStr(sTemp, "-")
Do While (nLen <> 0)
sTemp = Left(sTemp, nLen - 1) & Right(sTemp, Len(sTemp) - nLen)
nLen = InStr(sTemp, "-")
Loop
Else
sTemp = ""
End If
End If
UniqueValue = sTemp
End Function
สำหรับวีบี
ประยุกต์ใช้ครับ