VB 2010 - Action based on button text

I originally learned VB using VB6 and I am now learning VB 2010 and I learned a trick during VB6 class that I can't seem to repeat or remember the correct format. I have button1 with the text "ENTER" and when I click the button I want an action to occur, like the background changing color. Also, when the button is clicked I want the text to change on the button to "FLIP." Then when the user clicks the button it executes a different action because the text in the button is "FLIP" not "ENTER." The code below shows you what I am trying to do but it will not go work. I basically want one button to do two things and I used to be able to do it but I can't remember how.

 If Button1.Text = "ENTER" Then
            Me.BackColor = Color.Brown
            Button1.Text = "FLIP"

        ElseIf Button1.Text = "FLIP" Then
            Me.BackColor = Color.Gold
            Button1.Text = "ENTER"

        End If
Matthew_BAsked:
Who is Participating?
 
Éric MoreauConnect With a Mentor Senior .Net ConsultantCommented:
it should be working.
0
 
Éric MoreauConnect With a Mentor Senior .Net ConsultantCommented:
I just tested it and it is working (as long as your initial text value is either ENTER or FLIP)
0
 
tring_tringConnect With a Mentor Commented:
That code should let you perform different actions depending on the text of button. However if you are trying to change the backcolor it won't work this way,
Also where are you placing the code. It should be placed in the function invoked on button click for instance:-

 Protected Sub btnExchange_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExchange.Click
        If btnExchange.Text = "Exchange" Then
            btnExchange.Text = "1"
        ElseIf 1 = 1 Then
            btnExchange.Text = "Exchange"
        End If
    End Sub
0
 
CodeCruiserConnect With a Mentor Commented:
One change you may want to do is

If Button1.Text.ToUpper = "ENTER" Then
            Me.BackColor = Color.Brown
            Button1.Text = "FLIP"

        ElseIf Button1.Text.ToUpper = "FLIP" Then
            Me.BackColor = Color.Gold
            Button1.Text = "ENTER"

        End If
0
 
Matthew_BAuthor Commented:
I sincerely apologize for the confusion. I have no idea what had happened, but when I was working at home the code just would NOT work. I cam to work and tried it again after reading everyone's replies and it worked fine. I must have left out a statement on accident. Either that or I should stop writing code in the middle of the night.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.