i got a homework its about Generate code
Name: qwerty
Year Enrolled: 2008
IDNum: 123mem

Button: GENERATE CODE

Code: 083memrty

{ 2 last degit from year became the 2 first, 4 last from IDNum became 4 next, 3 last from name became 3 next= 083memrty}

1. validate the text boxes for presence
2. validate year for format (should be numeric and 4 chars)
3. i already explain how to get the code.

any help plz

my firt code:

Private Sub cmdGenerateCode_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGenerateCode.Click
        Dim YE As String = txtYearEnrolled.Text
        If (txtName.Text = "") Then
            MsgBox("Name text box is empty")
        ElseIf (txtYearEnrolled.Text = "") Then
            MsgBox("Year Enrolled Text box is empty")
        ElseIf YE < YE.Chars(4) Then
            MsgBox("Year Enrolled text box comtain more than 4 number")
        ElseIf Not IsNumeric(txtYearEnrolled.Text) Then
            MsgBox("Year Enrolled is not a numeric")
        End If

i got problem here:

ElseIf YE < YE.Chars(4) Then

Recommended Answers

All 4 Replies

Try This :

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Name, Id, ye, Gen As String

        Name = txtName.Text
        Ye = txtYearEnrolled.Text
        Id = txtIDNum.Text

        Gen = Microsoft.VisualBasic.Right(ye, 2) + Microsoft.VisualBasic.Right(Id, 4) + Microsoft.VisualBasic.Right(Name, 3)

        If Name = "" Then
            MsgBox("Name is empty")
        ElseIf ye = "" Then
            MsgBox("Year is empty")
        ElseIf Id = "" Then
            MsgBox("Id Number is empty")
        ElseIf txtYearEnrolled.TextLength > 4 Then
            MsgBox("Year Enrolled text box comtain more than 4 number")
        ElseIf Not IsNumeric(txtYearEnrolled.Text) Then
            MsgBox("Year Enrolled is not a numeric")
        Else
            MsgBox(Gen)
        End If
    End Sub
commented: nice +1

Thanks
any problem i'll post it

Help How to Break these Info (name year and Id) to make the code
(read on first post for the code)

i cant use char
plz help

i did'tn get what u want exactly...
this part code is how to get string from name, id and year.

Gen = Microsoft.VisualBasic.Right(ye, 2) + Microsoft.VisualBasic.Right(Id, 4) + Microsoft.VisualBasic.Right(Name, 3)

Right Function used to get some string from string as many as u want.
Right(SourceString (String), how much string to get (Int)).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.