I recently read an article about how to obtain necessary information through the ID card number. I think that when I was using the MS system, I usually need to enter the ID card number, gender, and date of birth, these inputs can be obtained only through the ID card, which should be repeated input. In addition, the consistency between the gender and birth date and the ID card can be verified to avoid input errors, the code below is a self-written code that obtains the necessary information through a 15-and 18-digit ID card. It is also fun.
Code
Option explicit
'Id card type
'Get gender and Date of Birth through ID card number
Private ID _ as string
Private const idcard_length_description as string = "ID card number must be 15 or 18 characters"
'Id card No.
Public property get ID () as string
Assert Len (ID _) = 15 or Len (ID _) = 18, me, "ID", idcard_length_description
Id = ID _
End Property
Public property let ID (byval Sid as string)
Assert Len (SID) = 15 or Len (SID) = 18, me, "ID", idcard_length_description
ID _ = Sid
End Property
'Id No. Length
Public property get idlength () as integer
Idlength = Len (ID _)
End Property
'Gender
Public property get sex () as string
Dim stemp as string
Assert idlength = 15 or idlength = 18, me, "sex", idcard_length_description
Select case idlength
Case 15
Stemp = mid (ID _, 13, 3)
Case 18
Stemp = mid (ID _, 3, 15)
End select
If CINT (stemp) mod 2 = 0 then
Sex = "female"
Else
Sex = "male"
End if
End Property
'Birthdate
Public property get birthday () as string
Dim stemp as string
Assert idlength = 15 or idlength = 18, me, "Birthday", idcard_length_description
Select case idlength
Case 15
Stemp = mid (ID _, 7, 6)
Stemp = "19" & stemp
Case 18
Stemp = mid (ID _, 7, 8)
End select
Birthday = mid (stemp, 1, 4) & "/" & Mid (stemp, 5, 2) & "/" & Mid (stemp, 7, 2)
End Property