-
Notifications
You must be signed in to change notification settings - Fork 3
/
M_omGuidFunctions.def
33 lines (31 loc) · 1 KB
/
M_omGuidFunctions.def
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
33
Option Compare Database
Option Explicit
Private Declare PtrSafe Function CoCreateGuid Lib "ole32" (Id As Any) As Long
Public Function CreateGuid() As String
Dim Id(0 To 15) As Byte
Dim cnt As Long, Guid As String
If CoCreateGuid(Id(0)) = 0 Then
For cnt = 0 To 15
CreateGuid = CreateGuid + IIf(Id(cnt) < 16, "0", "") + Hex$(Id(cnt))
Next cnt
CreateGuid = Left$(CreateGuid, 8) + "-" + Mid$(CreateGuid, 9, 4) + "-" + Mid$(CreateGuid, 13, 4) + "-" + Mid$(CreateGuid, 17, 4) + "-" + Right$(CreateGuid, 12)
Else
MsgBox "Error while creating GUID!"
End If
End Function
Public Function CreateRandomEAN13() As String
Dim cnt As Long
Dim i As Long
Dim seed As String
Dim S As String
seed = CreateGuid() & CreateGuid & CreateGuid() & CreateGuid
i = 1
While cnt < 13
S = Mid(seed, i, 1)
If IsNumeric(S) Then
CreateRandomEAN13 = CreateRandomEAN13 & S
cnt = cnt + 1
End If
i = i + 1
Wend
End Function