Community

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

Данные поля часто встречаются в различных финансовых документах. ОГРН содержит 13 цифр, ОГРНИП – 15 цифр


Dim vField, vField1, vLen, vCRC

vField = me.Field("GosRegNum").Text

vLen = Len(vField)
Dim separator
separator = Mid( CStr(1.1),2,1)

if vLen = 13 then
vField1 = Mid(vField, 1, 12)
vCRC = Mid (vField, 13, 1)

if IsNumeric(vCRC) and IsNumeric(vField1) then
vField1 = Round (vField1/11, 2)
vField1 = CStr(vField1)
vField1 = "0" & Mid (vField1, Len (vField1) - 2, 3)

if separator = "." then
vField1 = Replace (vField1, ",", ".")
else
vField1 = Replace (vField1, ".", ",")
end if

vField1 = CInt(vField1*11)

if vField1 = 10 then
vField1 = 0
vCRC = "0"
end if

if vField1 <> CInt(vCRC) then
me.CheckSucceeded = False
me.ErrorMessage = "Некорректный формат ОГРН"
end if
end if
elseif vLen = 15 then
vField1 = Mid(vField, 1, 14)
vCRC = Mid (vField, 15, 1)

if IsNumeric(vCRC) and IsNumeric(vField1) then
vField1 = Round (vField1/13, 2)
vField1 = CStr(vField1)
vField1 = "0" & Mid (vField1, Len (vField1) - 2, 3)

if separator = "." then
vField1 = Replace (vField1, ",", ".")
else
vField1 = Replace (vField1, ".", ",")
end if

vField1 = CInt(vField1*13)

if vField1 = 10 then
vField1 = 0
vCRC = "0"
end if

if vField1 <> CInt(vCRC) then
me.CheckSucceeded = False
me.ErrorMessage = "Некорректный формат ОГРНИП"
end if
end if

end if

0

Comments

0 comments

Please sign in to leave a comment.