0

The first IF statement is really working good and the other IF statements that follow do not work. When I click the button nothing happens.

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    If TextBox1.Text.Trim = "What is your name?" Then
        Label1.Text = "Hi there kid! I will tell you later!"
        Return
        If TextBox1.Text.Trim = "What is your age?" Then
            Label1.Text = "I was made in January 31,2014 well that is my birth date!"
            Return



            If TextBox1.Text = "Hi" Then
                Label1.Text = "Hi there also!"

            Else
                Label1.Text = "Do you have anything you want to say other than that?"
            End If
        End If
    End If
End Sub
DeanOC
  • 7,142
  • 6
  • 42
  • 56
TheNewbie
  • 112
  • 1
  • 6
  • 15
  • Using "Return" exits out of your event handler – Jesse Jan 31 '14 at 00:55
  • @Jesse when i removed Return it still acts the same.. :*( – TheNewbie Jan 31 '14 at 00:57
  • 1
    Your ifs are also nested, it's impossible for TextBox1.Text.Trim to equal "What is your age?" if it's already equal to "What is your name?". – Jesse Jan 31 '14 at 00:59
  • You need to add some detail on how you think it should work. – Jesse Jan 31 '14 at 00:59
  • @Ken White No sir...that topic does not answer my question :) – TheNewbie Jan 31 '14 at 01:06
  • @TheNewbie We really all want to help each other... But for the time being, you should really spend a little bit more time analyzing your code before you post a question. I'm not saying the question is annoying, NOT AT ALL, but to be a good programmer, you must allow yourself to think first before finally giving up if all else fails :) The time you spend thinking, regardless if you get the answer or not, will definitely improve your algorithm skills :) – chris_techno25 Jan 31 '14 at 01:12
  • It's the same question (My if statement isn't working), with almost the identical same code. I still think it's a duplicate. I also think you should learn to use the debugger, which would help you solve your problems like this yourself. :-) – Ken White Jan 31 '14 at 01:13
  • @KenWhite Ok forgive me because I am just a beginner programmer :) Thanks for your concern anyway :) It is identical in a way that it is my starting code and I added new codes which gave me a new dilemma. – TheNewbie Jan 31 '14 at 01:14
  • You've posted two questions with almost identical code in less than an hour. Spend some time trying to figure things out yourself before posting here (as I said, start with the debugger - it's great when you're learning, because you can actually solve the problem and learn in the process). – Ken White Jan 31 '14 at 01:17
  • @KenWhite Hi Sir, I've posted a question that nobody answered :( Here's the link... http://stackoverflow.com/questions/21454519/difference-between-connectioninfo-class-and-crystal-reports-datasourceconnectio Can you please help me on this? Thank you :) – chris_techno25 Jan 31 '14 at 01:23

2 Answers2

2

I think you can remove return and use else if for the other if. it should be fine

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    If TextBox1.Text.Trim = "What is your name?" Then
        Label1.Text = "Hi there kid! I will tell you later!"

    else if TextBox1.Text.Trim = "What is your age?" Then
        Label1.Text = "I was made in January 31,2014 well that is my birth date!"

    else if TextBox1.Text = "Hi" Then
        Label1.Text = "Hi there also!"

    Else
        Label1.Text = "Do you have anything you want to say other than that?"

    End If

End Sub
Murat Çorlu
  • 8,207
  • 5
  • 53
  • 78
joy
  • 130
  • 3
  • many thanks this code that you gave worked like a charm however i removed the 2 end ifs because it is not necessary :) – TheNewbie Jan 31 '14 at 01:13
0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    If TextBox1.Text.Trim = "What is your name?" Then
        Label1.Text = "Hi there kid! I will tell you later!"
    End If
    If TextBox1.Text.Trim = "What is your age?" Then
        Label1.Text = "I was made in January 31,2014 well that is my birth date!"
    End If
    If TextBox1.Text = "Hi" Then
        Label1.Text = "Hi there also!"
    Else
        Label1.Text = "Do you have anything you want to say other than that?"
    End If
End Sub

Try that

Wayne In Yak
  • 546
  • 1
  • 4
  • 21