View Full Version : Writing code for ID numbers in VB.NET
Mistery1
Jan 7, 2009, 05:57 AM
HI there,
Please can you help me in writing code for ID numbers in VB.NET.
I want, When someone fills in their ID number It should tell them if it is valid or not and if the person is a male or female.
StaticFX
Jan 8, 2009, 01:11 PM
??
More info needed.. where is the ID numbers stored?
Mistery1
Jan 9, 2009, 01:21 AM
HI,
On the front end(GUI), when the user enters his\her ID number it should bring up a message box saying that the ID number is correct or not. And the code should also pick up from the id number whether the person is a male or female and automatically check the radio button in the form.
I need to know how to code this according to the ffg:
Format:
{YYMMDD}{G}{SSS}{C}{A}{Z}
YYMMDD : Date of birth.
G : Gender. 0-4 Female; 5-9 Male.
SSS : Sequence No. for DOB/G combination.
C : Citizenship. 0 SA; 1 Other.
StaticFX
Jan 9, 2009, 06:30 AM
This should get you started:
Add a button.. say btn_Decode
In the click event
Decode(txtIDnum.text)
And then this code...
Private Sub Decode(ByVal IDnum As String)
'check to make sure its 13 chars long
If IDnum.Length <> 13 Then MsgBox("Incorrect ID. Please check and try again", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly, "Error!") : Exit Sub
Dim DOB As String = IDnum.Substring(2, 2) & "/" & IDnum.Substring(4, 2) & "/" & IDnum.Substring(0, 2)
If Not IsDate(DOB) Then
MsgBox("The birthdate in the ID appears to be incorrect! Please re-check", MsgBoxStyle.Exclamation, "Error!")
End If
txtDate.text = DOB
Select Case IDnum.Substring(6, 1)
Case 1 To 4
rdoFemale.checked = True
Case 5 To 9
rdoMale.checked = True
End Select
txtSSS.text = IDnum.Substring(7, 3)
If IDnum.Substring(10, 1) = 0 Then
rdoC_SA.checked = True
Else
rdoC_Othr.checked = True
End If
End Sub
You will need to add the appropriate (or change the names of the) fields
Let me know if you need more help
Mistery1
Jan 23, 2009, 08:11 AM
Hi there,
Thanks for your help, I'm new at vb.net and I struggled and struggled and I still can't get it right. For some strange reason its not working. Is there any other easier code that I could test.
Thanks
StaticFX
Jan 23, 2009, 08:25 AM
What's not working? I just tested this and it works perfectly...
Do you have the controls added?
You need
3 textboxes:
TxtDate
TxtSSS
TxtIDNUM
2 Groupboxes (for grouping the RadioButtons)
In Groupbox1:
2 RadioButtons
RdoFemale
RdoMale
In groupbox2
2 radiobuttons
RdoC_SA
RdoC_Othr
1 Button (next to txtIDNUM)
In the click event of the button
Decode(txtIDNUM.text)
That's it
Mistery1
Jan 26, 2009, 11:52 PM
hi there,
I get these errors
Index and length must refer to a location within the string. Parameter name: length.
At this part of the code - Dim DOB As String = IDnum.Substring(2, 2) & "/" & IDnum.Substring(4, 2) & "/" & IDnum.Substring(0, 2)
And this error - startIndex cannot be larger than length of string. Parameter name: startIndex
At this part of the code - Select Case IDnum.Substring(6, 1)