Ask Experts Questions for FREE Help !
Ask
    Mistery1's Avatar
    Mistery1 Posts: 39, Reputation: 1
    Junior Member
     
    #1

    Jan 7, 2009, 05:57 AM
    Writing code for ID numbers in VB.NET
    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's Avatar
    StaticFX Posts: 943, Reputation: 74
    Senior Member
     
    #2

    Jan 8, 2009, 01:11 PM

    ??

    More info needed.. where is the ID numbers stored?
    Mistery1's Avatar
    Mistery1 Posts: 39, Reputation: 1
    Junior Member
     
    #3

    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's Avatar
    StaticFX Posts: 943, Reputation: 74
    Senior Member
     
    #4

    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...

    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's Avatar
    Mistery1 Posts: 39, Reputation: 1
    Junior Member
     
    #5

    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's Avatar
    StaticFX Posts: 943, Reputation: 74
    Senior Member
     
    #6

    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's Avatar
    Mistery1 Posts: 39, Reputation: 1
    Junior Member
     
    #7

    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)

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

I just want to know p are in writing minutes and what really writing [ 3 Answers ]

I just want to know the procedures in writing minutes and what really entails in writing minutes.

BIG Numbers! [ 7 Answers ]

What is the BIGGEST NUMBER that you can think of (name number, count digits and type number)?!

Letters are numbers and num lock off no numbers [ 2 Answers ]

I cannot get my hp pavilion notebook to respond, it started all of a sudden. When my num lock is on my letters on the keyboard turn into numbers... I=5 and so forth. Now when my num lock is off my keyboard works fine but I cannot use the number pad. I tried the fn key with almost every key on the...

1989 honda civic. (code 4)crank angle sensor.(code 8) tdc position sensor [ 0 Answers ]

The car idles randomly after warm up.I check the ecu for codes and it gives 4 crank angle sensor and 8 tdc position sensor. I did a search and one of the ad posted by a guy in Canada says that he had to get part from different vehicles until he got all of them to work properly. Will I be able to...


View more questions Search