|
-
Oct 10th, 2012, 08:29 PM
#1
Thread Starter
Addicted Member
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
-
Oct 10th, 2012, 09:21 PM
#2
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
-
Oct 10th, 2012, 09:21 PM
#3
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.
-
Oct 11th, 2012, 07:27 PM
#4
Thread Starter
Addicted Member
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.
-
Oct 11th, 2012, 07:36 PM
#5
Re: How to delay button commands.. One click = one command at a time.
 Originally Posted by Reapism
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.
-
Oct 11th, 2012, 07:42 PM
#6
Thread Starter
Addicted Member
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.
-
Oct 11th, 2012, 07:44 PM
#7
Thread Starter
Addicted Member
Re: How to delay button commands.. One click = one command at a time.
O this is cool! Thanks man!
-
Oct 11th, 2012, 08:17 PM
#8
Re: How to delay button commands.. One click = one command at a time.
 Originally Posted by Reapism
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?
-
Oct 12th, 2012, 02:32 AM
#9
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|