我需要检查 JMBG(我所在国家/地区的唯一公民号码)。它有 13 个数字,由以下代码计算得出。该函数返回我的 JMBG 错误。也许在代码的某个地方我做了错误的计算。
这是一个例子。现实生活中的 JMBG 是 0805988212987,这个函数返回错误的月份。
Function Check_JMBG(JMBG As String) As String
' Function returns message with notification of JMBG validation
' JMBG has 13 numbers and can be treated like this when checking it DD.MM.GGG.OO.BBB.K
' Details of JMBG (unique citizenship number in my country, is 13 by the way):
'DD - day of birth
'MM - manth of birth
'GGG - last 3 numbers of year of birth, starting from (1)899. year
'OO - municipality birth code
'BBB - serial number of birth person. Man from 001-499, woman from 501-999
'K - control number, modulo 11
Dim size As Integer, sum As Integer
Dim number(1 To 13) As Integer
Dim day As Integer, manth As Integer, year As String
size = Len(JMBG)
day = Int(Left(JMBG, 2))
manth = Int(Mid$(JMBG, 3, 2))
year = Mid$(JMBG, 5, 3)
' Size check
If (size <> 13) Then
Check_JMBG = "ERR: size of JMBG is not 13!"
End If
'Date check
If day < 1 Then
Check_JMBG = "ERR: date entered is wrong!"
Exit Function
End If
'Manth check and date inside manth
Select Case manth
Case 1, 3, 5, 7, 8, 10, 12
If day > 31 Then
Check_JMBG = "ERR: date number is wrong!"
Exit Function
End If
Case 4, 6, 9, 11
If day > 30 Then
Check_JMBG = "ERR: data number is wrong!"
Exit Function
End If
Case 2
If ((year Mod 4 = 0) And day > 29) Or _
((year Mod 4 <> 0) And day > 28) Then
Check_JMBG = "ERR: date number is wrong!"
Exit Function
End If
Case Else
Check_JMBG = "ERR: manth number is wrong!"
Exit Function
End Select
'Check year: from 1899 till today
If (year > Right(str(Year(Now)), 3)) And (year < "899") Then
Check_JMBG = "ERR: year number is wrong!"
Exit Function
End If
'Control number check
For i = 1 To 13
number(i) = Int(Mid$(JMBG, i, 1))
Next i
sum = number(13) + number(1) * 7 + number(2) * 6
sum = sum + number(3) * 5 + number(4) * 4
sum = sum + number(5) * 3 + number(6) * 2
sum = sum + number(7) * 7 + number(8) * 6
sum = sum + number(9) * 5 + number(10) * 4
sum = sum + number(11) * 3 + number(12) * 2
If (sum Mod 11) <> 0 Then
Check_JMBG = "ERR: wrong control number!"
Else
Check_JMBG = "JMBG is correct"
End If
End Function