在access中应用Lunh算法
Apply Lunh algorithm in access
有人知道如何在访问中应用 Lahn 算法,以使用 phone 号码
验证参考号码
此函数将为您计算校验位:
Public Function Modulus1x(ByVal strNum As String, ByVal intModulus As Integer) As Integer
' Creates the Modulus-10 or -11 check digit for strNum.
' Non-numeric characters are ignored.
' Maximum length of number.
Const cintNumLenMax = 31
Dim strTmp As String
Dim intChr As Integer
Dim intLen As Integer
Dim intSum As Integer
Dim intVal As Integer
Dim intWeight As Integer
Dim intCount As Integer
Dim intChk As Integer
Select Case intModulus
Case 10, 11
intLen = Len(strNum)
If intLen > 0 Then
' Remove non-numeric characters.
For intCount = 1 To intLen
intChr = Asc(Mid(strNum, intCount))
If intChr >= 48 And intChr <= 57 Then
strTmp = strTmp & Chr(intChr)
End If
Next intCount
strNum = strTmp
intLen = Len(strNum)
If intLen > 0 Then
' Calculate check digit.
If intLen <= cintNumLenMax Then
For intCount = 1 To intLen
intVal = Val(Mid(strNum, intLen - intCount + 1, 1))
Select Case intModulus
Case 10
intWeight = 1 + (intCount Mod 2)
intVal = intWeight * intVal
intVal = Int(intVal / 10) + (intVal Mod 10)
Case 11
intWeight = 2 + ((intCount - 1) Mod 6)
intVal = intWeight * intVal
End Select
intSum = intSum + intVal
Next intCount
intChk = -Int(-intSum / intModulus) * intModulus - intSum
End If
End If
End If
End Select
Modulus1x = intChk
End Function
只需传递phone号码:
PhoneNumber = "+01234568790"
CheckDigit = Modulus1x(PhoneNumber, 10)
PhoneNumberWithCheckDigit = PhoneNumber & CheckDigit
以及这里的函数:
您可以验证 PhoneNumberWithCheckDigit
有人知道如何在访问中应用 Lahn 算法,以使用 phone 号码
验证参考号码此函数将为您计算校验位:
Public Function Modulus1x(ByVal strNum As String, ByVal intModulus As Integer) As Integer
' Creates the Modulus-10 or -11 check digit for strNum.
' Non-numeric characters are ignored.
' Maximum length of number.
Const cintNumLenMax = 31
Dim strTmp As String
Dim intChr As Integer
Dim intLen As Integer
Dim intSum As Integer
Dim intVal As Integer
Dim intWeight As Integer
Dim intCount As Integer
Dim intChk As Integer
Select Case intModulus
Case 10, 11
intLen = Len(strNum)
If intLen > 0 Then
' Remove non-numeric characters.
For intCount = 1 To intLen
intChr = Asc(Mid(strNum, intCount))
If intChr >= 48 And intChr <= 57 Then
strTmp = strTmp & Chr(intChr)
End If
Next intCount
strNum = strTmp
intLen = Len(strNum)
If intLen > 0 Then
' Calculate check digit.
If intLen <= cintNumLenMax Then
For intCount = 1 To intLen
intVal = Val(Mid(strNum, intLen - intCount + 1, 1))
Select Case intModulus
Case 10
intWeight = 1 + (intCount Mod 2)
intVal = intWeight * intVal
intVal = Int(intVal / 10) + (intVal Mod 10)
Case 11
intWeight = 2 + ((intCount - 1) Mod 6)
intVal = intWeight * intVal
End Select
intSum = intSum + intVal
Next intCount
intChk = -Int(-intSum / intModulus) * intModulus - intSum
End If
End If
End If
End Select
Modulus1x = intChk
End Function
只需传递phone号码:
PhoneNumber = "+01234568790"
CheckDigit = Modulus1x(PhoneNumber, 10)
PhoneNumberWithCheckDigit = PhoneNumber & CheckDigit
以及这里的函数:
您可以验证 PhoneNumberWithCheckDigit