VS 2010 How to delay button commands.. One click = one command at a time.-VBForums
Results 1 to 9 of 9

Thread: How to delay button commands.. One click = one command at a time.

  1. #1

    Thread Starter
    Lively Member Reapism's Avatar
    Join Date
    Sep 2012
    Posts
    120

    Exclamation How to delay button commands.. One click = one command at a time.

    Code:
       Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Button1.Text = "1"
            Button1.Text = "+"
            Button1.Text = "2"
            Button1.Text = "="
            Button1.Text = "3"

    Essentially making it 5 buttons clicks to reach "3"

    Problem: Runs all commands and ends up at 3.

    Additional information:
    I was informed by my programming teacher that adding a loop should do it but I am not entirely sure... If so, How do I do it?

    Program: Visual Studio 2010 Language: Visual Basics

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    12,138

    Re: How to delay button commands.. One click = one command at a time.

    Well one option would be to use a Select Case there
    Code:
    Select Case Button1.Text
       Case "1"
           Button1.Text="+"
       Case "+"
           Button1.Text="2"
    ' and so on
    
    End Select

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    96,546

    Re: How to delay button commands.. One click = one command at a time.

    To be clear, you're saying that the first time the user clicks the Button it should display "1", then the second time they click it it should display "+", then the third time "2" and so on, correct? That's the kind of clarity you need to provide when you describe your problem to people who have no prior knowledge of it. The more we have to assume or guess, the more likely we get it wrong. Provide a FULL and CLEAR description.

    Assuming that that is correct, a loop won't help. You should create an array containing those Strings and assign it to a member variable. You'll want another variable to store the index of the current text, which will start at -1. Each click, increment the index variable and then get the String at that index in the array and display it.

    The only issue then is what to do when you get to the end of the array. The two most obvious options are you simply do nothing id the index goes past the upper bound of the array or you wrap back to zero and start again.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Lively Member Reapism's Avatar
    Join Date
    Sep 2012
    Posts
    120

    Re: How to delay button commands.. One click = one command at a time.

    I appreciate your tips. I'm just throwing this out there, I struggle when I try to explain a problem I have, Its one of my weaknesses. But what you stated was correct and you were able to interpret my failure to properly address my problem. I do not have 77,000+ posts like you I have around 10 I am new to the forums and i'm sorry I'm not as experienced. I will keep in mind I have to be more explanatory.

  5. #5
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    96,546

    Re: How to delay button commands.. One click = one command at a time.

    Quote Originally Posted by Reapism View Post
    I appreciate your tips. I'm just throwing this out there, I struggle when I try to explain a problem I have, Its one of my weaknesses. But what you stated was correct and you were able to interpret my failure to properly address my problem. I do not have 77,000+ posts like you I have around 10 I am new to the forums and i'm sorry I'm not as experienced. I will keep in mind I have to be more explanatory.
    You don't have to be an experienced programmer to explain how an application needs to work from the user's perspective. In fact, how the application needs to work from the user's perspective has absolutely nothing to do with programming. There are lots of people who couldn't program a lick but could tell you way more than I could about how to use various programs.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Lively Member Reapism's Avatar
    Join Date
    Sep 2012
    Posts
    120

    Re: How to delay button commands.. One click = one command at a time.

    Thank you, that actually made me think a bit. But what I meant is explaining a problem with anything in life is quite difficult. I am in the Intro programming class in school and I cant use methods,terms etc. to help me explain. I really appreciate your help man. It's truly an honor.

  7. #7

    Thread Starter
    Lively Member Reapism's Avatar
    Join Date
    Sep 2012
    Posts
    120

    Re: How to delay button commands.. One click = one command at a time.

    O this is cool! Thanks man!

  8. #8
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    96,546

    Re: How to delay button commands.. One click = one command at a time.

    Quote Originally Posted by Reapism View Post
    O this is cool! Thanks man!
    I take it that that means that you've tried the suggestion with some success. It is a bit of a thrill to see things happen on the screen and know that the code you wrote caused it. The power is intoxicating, yes?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9
    Frenzied Member
    Join Date
    Dec 2007
    Posts
    1,071

    Re: How to delay button commands.. One click = one command at a time.

    I'm a bit rusty but...

    Code:
    Dim values() As String = {"1", "+", "2", "=", "3"}
    Dim index As Integer = 0
    While index < values.Length
        If ButtonName.Text = values(index) Then
             ButtonName.Text = values(IIf(index + 1 >= values.length, 0, index + 1))
             Exit While
        End If
        index += 1
    End While
    If ButtonName.Text.Length = 0 Then
        ButtonName.Text = values(0)
    End If

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.