Community

Проверка контрольной суммы ИНН


Dim vFieldVal, vFieldName, L, i

vFieldName = "INN"

vFieldVal = me.FIELD(vFieldName).TEXT

vFieldVal = Replace (vFieldVal, vbCR, "")
vFieldVal = Replace (vFieldVal, vbLF, "")
vFieldVal = Replace (vFieldVal, " ", "")

'------------------------------- проверка корпоративного ИНН -------------------------------------------------
L = Len (vFieldVal)
Dim InnIsCorrect

for i = 1 to L
if not IsNumeric (Mid(vFieldVal, i, 1)) Then
me.CheckSucceeded = False
me.ErrorMessage = "В поле должны быть только цифры"
Exit Sub
end if

next

Dim a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12
if L = 10 then
a1 = CInt(Mid(vFieldVal, 1, 1))
a2 = CInt(Mid(vFieldVal, 2, 1))
a3 = CInt(Mid(vFieldVal, 3, 1))
a4 = CInt(Mid(vFieldVal, 4, 1))
a5 = CInt(Mid(vFieldVal, 5, 1))
a6 = CInt(Mid(vFieldVal, 6, 1))
a7 = CInt(Mid(vFieldVal, 7, 1))
a8 = CInt(Mid(vFieldVal, 8, 1))
a9 = CInt(Mid(vFieldVal, 9, 1))
a10 = CInt(Mid(vFieldVal, 10, 1))

InnIsCorrect = (a10 = ((a1 * 2 + a2 * 4 + a3 * 10 + a4 * 3 + a5 * 5 + a6 * 9 + a7 * 4 + a8 * 6 + a9 * 8) Mod 11) Mod 10)
' 2, 4, 10, 3, 5, 9, 4, 6, 8

if InnIsCorrect = 0 then
me.ERRORMESSAGE = "Некорректный формат ИНН"
me.CHECKSUCCEEDED = false
me.FOCUSEDFIELD = me.FIELD (vFieldName)
end if
'------------------------ проверка персонального ИНН ------------------------
elseif L = 12 then
a1 = CInt(Mid(vFieldVal, 1, 1))
a2 = CInt(Mid(vFieldVal, 2, 1))
a3 = CInt(Mid(vFieldVal, 3, 1))
a4 = CInt(Mid(vFieldVal, 4, 1))
a5 = CInt(Mid(vFieldVal, 5, 1))
a6 = CInt(Mid(vFieldVal, 6, 1))
a7 = CInt(Mid(vFieldVal, 7, 1))
a8 = CInt(Mid(vFieldVal, 8, 1))
a9 = CInt(Mid(vFieldVal, 9, 1))
a10 = CInt(Mid(vFieldVal, 10, 1))
a11 = CInt(Mid(vFieldVal, 11, 1))
a12 = CInt(Mid(vFieldVal, 12, 1))

if a11 <> ((a1 * 7 + a2 * 2 + a3 * 4 + a4 * 10 + a5 * 3 + a6 * 5 + a7 * 9 + a8 * 4 + a9 * 6 + a10 * 8) Mod 11) Mod 10 Then
' 7, 2, 4, 10, 3, 5, 9, 4, 6, 8
me.ERRORMESSAGE = "Некорректный формат ИНН"
me.CHECKSUCCEEDED = false
me.FOCUSEDFIELD = me.FIELD (vFieldName)
Exit Sub
End If
if (a12 <> ((a1 * 3 + a2 * 7 + a3 * 2 + a4 * 4 + a5 * 10 + a6 * 3 + a7 * 5 + a8 * 9 + a9 * 4 + a10 * 6 + a11 * 8) Mod 11) Mod 10) Then
' 3, 7, 2, 4, 10, 3, 5, 9, 4, 6, 8
me.ERRORMESSAGE = "Некорректный формат ИНН"
me.CHECKSUCCEEDED = false
me.FOCUSEDFIELD = me.FIELD(vFieldName)
Exit Sub
End If

end if
' ------------------------ запись значений в поля --------------------------------------------
me.FIELD(vFieldName).TEXT = vFieldVal

0

Comments

0 comments

Please sign in to leave a comment.