Access Serial Number VB Programming

Joined
Mar 29, 2011
Messages
1
Reaction score
0
Please someone Help me. I have a Key generator in ms access form which generate Serial keys; Ie the Key is [TLZEG-KXAMF-IHIXT-NEIRC-XEFCT]
But it doesn’t work on the following code
Public Function ValidateKey(strKey1 As String, strKey2 As String, strKey3 As String, _
strKey4 As String, strKey5 As String) As Boolean
'Variables
Dim i As Integer
Dim strKey As String
Dim strChr As String
Dim strNum As String
Dim strCode As String
Dim strTemp As String
Dim strTemp2 As String
Dim intTemp As Integer
'No Blanks
If Trim(strKey1) = "" Or Trim(strKey2) = "" Or Trim(strKey3) = "" Or _
Trim(strKey4) = "" Or Trim(strKey5) = "" Then
ValidateKey = False
Exit Function
End If
'All Must Be 5Chrs
If Len(strKey1) <> 5 Or Len(strKey2) <> 5 Or Len(strKey3) <> 5 Or _
Len(strKey4) <> 5 Or Len(strKey5) <> 5 Then
ValidateKey = False
Exit Function
End If
'Last Char of Key5 Must be the First Char of Key1
If Mid(strKey1, 1, 1) <> Right(strKey5, 1) Then
ValidateKey = False
Exit Function
End If
'Setup Key
strKey = strKey1 & strKey2 & strKey3 & strKey4 & strKey5
'Assemble String of 10 Characters
strChr = Mid(strKey, 1, 3) & Mid(strKey, 6, 2) & Mid(strKey, 9, 1) & _
Mid(strKey, 14, 3) & Mid(strKey, 19, 1)
'Assemble String of What will be 10 Numbers
strNum = Mid(strKey, 4, 2) & Mid(strKey, 8, 1) & Mid(strKey, 10, 4) & _
Mid(strKey, 17, 2) & Mid(strKey, 20, 1)
'Collect What will be the code
strCode = Right(strKey, 5)
'Make Sure 3 Characters in strCode Match with Appropriate Number and Alpha Keys
If Mid(strCode, 1, 1) <> Mid(strChr, 5, 1) Then
ValidateKey = False
Exit Function
End If
If Mid(strCode, 2, 1) <> Mid(strNum, 1, 1) Then
ValidateKey = False
Exit Function
End If
If Right(strCode, 1) <> Mid(strChr, 1, 1) Then
ValidateKey = False
Exit Function
End If
'Convert strNum Characters to ASC and Keep Last Digit
For i = 1 To Len(strNum)
strTemp = strTemp & Right(CStr((Asc(Mid(strNum, i, 1)) - 65)), 1)
Next
'Convert strChr Characters to ASC and Keep Last Digit
For i = 1 To Len(strChr)
strTemp2 = strTemp2 & Right(CStr((Asc(Mid(strChr, i, 1)))), 1)
Next
'The ASC in strTemp must match the asc in strTemp2
If strTemp <> strTemp2 Then
ValidateKey = False
Exit Function
End If
'Add Up SUm of Each Unique Number in ASC of Chr String
For i = 1 To Len(strNum)
intTemp = intTemp + CInt(Right(CStr((Asc(Mid(strNum, i, 1)) - 65)), 1))
Next
strTemp = CStr(intTemp)
'Resize the Code & Extract Num Val
strCode = Mid(strCode, 3, 2)
strCode = Right(CStr((Asc(Mid(strCode, 1, 1)) - 65)), 1) & _
Right(CStr((Asc(Mid(strCode, 2, 1)) - 65)), 1)
'Does the Extracted Num match the Group Sum?
If strTemp <> strCode Then
ValidateKey = False
Exit Function
End If
'Key Looks Good
ValidateKey = True
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top