[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

VB 2010 - Action based on button text

Posted on 2011-10-26
5
Medium Priority
?
310 Views
Last Modified: 2012-05-12
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
0
Comment
Question by:Matthew_B
5 Comments
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 1000 total points
ID: 37033035
it should be working.
0
 
LVL 70

Assisted Solution

by:Éric Moreau
Éric Moreau earned 1000 total points
ID: 37033066
I just tested it and it is working (as long as your initial text value is either ENTER or FLIP)
0
 
LVL 1

Assisted Solution

by:tring_tring
tring_tring earned 500 total points
ID: 37033200
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
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 500 total points
ID: 37034101
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
 

Author Comment

by:Matthew_B
ID: 37038954
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Integration Management Part 2
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question