Проверка ИНН (Бухгалтерия)

morpheus

скриптописец
07.08.2006
3 915
1
34
Украина, Киев
#1
Задача
бухгалтерская задача проверять ИНН при сохранении карточки на контрольную сумму (физ.лиц/юр.лица)

Информация - Форма проверки реквизитов

Решение
[codebox]Function CheckINN(sInn As String) As Boolean

' Функция проверки количества символов, и вывод соответствующей подфункции:

sInn = Trim$(sInn)

Select Case Len(sInn)

Case 10: Check= CheckINN10(sInn)
Case 12: Check= CheckINN12(sInn)

End Select

If Check = False Then Msgbox("Не корректный ИНН")

End Function


Function CheckINN10(sInn As String) As Boolean

' Функция проверки 10-тизначного ИНН

Dim i As Integer, s As String, j As Integer
Dim v(1 To 10) As Integer

v(1) = 2
v(2) = 4
v(3) = 10
v(4) = 3
v(5) = 5
v(6) = 9
v(7) = 4
v(8) = 6
v(9) = 8
v(10) = 0

For i = 1 To 10

s = Mid$(sInn, i, 1)

If Not Isnumeric(s) Then Exit Function

j = j + Cint(v(i)) * Cint(s)

Next i

j = j Mod 11

If j > 9 Then j = j Mod 10

CheckINN10 = (j = Cint(s))

End Function


Function CheckINN12(sInn As String) As Boolean

' Функция проверки 12-тизначного ИНН

Dim i As Integer, s As String, j As Integer
Dim v(1 To 12) As Integer

v(1) = 3
v(2) = 7
v(3) = 2
v(4) = 4
v(5) = 10
v(6) = 3
v(7) = 5
v(8) = 9
v(9) = 4
v(10) = 6
v(11) = 8
v(12) = 0

'j = 0

For i = 1 To 12

s = Mid$(sInn, i, 1)

If Not Isnumeric(s) Then Exit Function

j = j + Cint(v(i)) * Cint(s)

Next i

j = j Mod 11

If j > 9 Then j = j Mod 10

If j <> Cint(s) Then Exit Function

j = 0

For i = 1 To 11

j = j + Cint(v(i)) * Cint(Mid$(sInn, i, 1))

Next i

j = j Mod 11

If j > 9 Then j = j Mod 10

CheckINN12 = (j = Cint(s))

End Function[/codebox]

Обсуждение - тут

Реализровали
LIGHT
NickProstoNick
 
I

interrupt

Гость
#2
Представляю Вашему вниманию еще ряд функций для бухгалтерии.
Всего 4 функции и вспомоательная "ПроверкаСчета"

Код:
Function ПроверкаБИК(sBik As String) As Boolean
Dim i As Integer
sBik = Trim$(sBik)
If Len(sBik) <> 9 Then Exit Function
For i = 1 To 9
If Not Isnumeric(Mid$(sBik, i, 1)) Then Exit Function
Next i
ПроверкаБИК = True
End Function

Function ПроверкаКорСчета(sKSchet As String, sBik As String) As Boolean
sKSchet = Trim$(sKSchet)
If Len(sKSchet) <> 20 Then Exit Function
ПроверкаКорСчета = ПроверкаСчета("0" & Mid$(sBik, 5, 2) & sKSchet)
End Function

Function ПроверкаРасчСчета(sRSchet As String, sBik As String) As Boolean
sRSchet = Trim$(sRSchet)
If Len(sRSchet) <> 20 Then Exit Function
ПроверкаРасчСчета = ПроверкаСчета(Right$(sBik, 3) & sRSchet)
End Function

Function ПроверкаСчета(sSchet As String) As Boolean
Dim i As Integer, s As String, j As Integer, v As Variant

Redim v(22)
v(0) = 7
v(1) = 1
v(2) = 3
v(3) = 7
v(4) = 1
v(5) = 3
v(6) = 7
v(7) = 1
v(8) = 3
v(9) = 7
v(10) = 1
v(11) = 3
v(12) = 7
v(13) = 1
v(14) = 3
v(15) = 7
v(16) = 1
v(17) = 3
v(18) = 7
v(19) = 1
v(20) = 3
v(21) = 7
v(22) = 1

'v = Array(7, 1, 3, 7, 1, 3, 7, 1, 3, 7, 1, 3, 7, 1, 3, 7, 1, 3, 7, 1, 3, 7, 1)
For i = 1 To 23
s = Mid$(sSchet, i, 1)
If Not Isnumeric(s) Then Exit Function
j = j + ((Cint(v(i - 1)) * Cint(s)) Mod 10)
Next i
ПроверкаСчета = (j Mod 10 = 0)
End Function

Function ПроверкаИНН(sInn As String) As Boolean
Dim i As Integer
Dim s As String 
Dim j As Integer 
Dim v As Variant

sInn = Trim$(sInn)
Select Case Len(sInn)
Case 10
Redim v(9)
v(0) = 2
v(1)=4
v(2)=10
v(3)= 3
v(4)=5
v(5)=9
v(6)=4
v(7)=6
v(8)=8
v(9)=0
'v = Array(2, 4, 10, 3, 5, 9, 4, 6, 8, 0)
For i = 1 To 10
s = Mid$(sInn, i, 1)
If Not Isnumeric(s) Then Exit Function
j = j + Cint(v(i - 1)) * Cint(s)
Next i
Case 12
Redim v(11)
v(0) = 3
v(1) = 7
v(2) = 2
v(3) = 4
v(4) = 10
v(5) = 3
v(6) = 5
v(7) = 9
v(8) = 4
v(9) = 6
v(10) = 8
v(11) = 0
'v = Array(3, 7, 2, 4, 10, 3, 5, 9, 4, 6, 8, 0)
For i = 1 To 12
s = Mid$(sInn, i, 1)
If Not Isnumeric(s) Then Exit Function
j = j + Cint(v(i - 1)) * Cint(s)
Next i
j = j Mod 11
If j > 9 Then j = j Mod 10
If j <> Cint(s) Then Exit Function

v(0) = 7
v(1) = 2
v(2) = 4
v(3) = 10
v(4) = 3
v(5) = 5
v(6) = 9
v(7) = 4
v(8) = 6
v(9) = 8
v(10) = 0
v(11) = 0

j = 0
For i = 1 To 11
s = Mid$(sInn, i, 1)
j = j + Cint(v(i - 1)) * Cint(s)
Next i
Case Else
Exit Function
End Select
j = j Mod 11
If j > 9 Then j = j Mod 10
ПроверкаИНН = (j = Cint(s))
End Function
Все функции были проверены и использовались.
Автор функций не я, я взял их здесь и чуть поправил для лотусового бейсика (LS типа).