Function VINValidate(VINNumber As String) As Boolean
Dim charLocationValue(1 To 17) As Integer
charLocationValue(1) = 8
charLocationValue(2) = 7
charLocationValue(3) = 6
charLocationValue(4) = 5
charLocationValue(5) = 4
charLocationValue(6) = 3
charLocationValue(7) = 2
charLocationValue(8) = 10
charLocationValue(9) = 0
charLocationValue(10) = 9
charLocationValue(11) = 8
charLocationValue(12) = 7
charLocationValue(13) = 6
charLocationValue(14) = 5
charLocationValue(15) = 4
charLocationValue(16) = 3
charLocationValue(17) = 2
workingvinnumber = Trim(VINNumber)
If Len(VINNumber) <> 17 Then
VINValidate = False
Exit Function
End If
For x = 1 To 17
thisVINCharacter = Mid(workingvinnumber, x, 1)
Select Case thisVINCharacter
Case "A", "J", "1"
thisVINCharacterValue = 1
Case "B", "K", "S", "2"
thisVINCharacterValue = 2
Case "C", "L", "T", "3"
thisVINCharacterValue = 3
Case "D", "M", "U", "4"
thisVINCharacterValue = 4
Case "E", "N", "V", "5"
thisVINCharacterValue = 5
Case "F", "W", "6"
thisVINCharacterValue = 6
Case "G", "P", "X", "7"
thisVINCharacterValue = 7
Case "H", "Y", "8"
thisVINCharacterValue = 8
Case "R", "Z", "9"
thisVINCharacterValue = 9
Case "0"
thisVINCharacterValue = 0
Case "I", "O", "Q"
VINValidate = False
Exit Function
End Select
totalvalue = totalvalue + (thisVINCharacterValue * charLocationValue(x))
Next
calculatedCheckDigitValue = totalvalue Mod 11
If calculatedCheckDigitValue = 10 Then
calculatedCheckDigit = "X"
Else
calculatedCheckDigit = Trim(CStr(calculatedCheckDigitValue))
End If
actualCheckDigit = Mid(workingvinnumber, 9, 1)
If calculatedCheckDigit = actualCheckDigit Then
VINValidate = True
Else
VINValidate = False
End If
End Function