|
|
#1 (permalink) |
|
Kohaku
Join Date: Feb 2008
Location: Mississauga, Ontario, Canada
Posts: 3,079
![]() |
This is a question for all of you programmers. So I have to make a program which can do various things for school. I have a plan in mind, but don't know how to execute it.
I will only explain the part where I am having trouble. I have a label which changes when you press a button. This is all good, but what I want is to change the label to different things when you click many times. For example: 1 Click: Label will say Hi 2 Clicks: Label will say I'm fine Ect. What I am having trouble with is that the whole code executes in one click, making the end message come in one click. Here is my idea, which doesn't work. Code:
Private Sub btnHi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHi.Click
lblMessage.Text = "Hello!"
btnHi.Text = "How are you?"
If btnHi.Text = "How are you?" Then
lblMessage.Text = "I'm fine, you?"
End If
End Sub
What I want is that the button says How are you? and then the user has to click on it to make the next message appear. How can I do this? |
|
|
|
|
|
#2 (permalink) |
|
Chrono's Crony
Join Date: May 2006
Location: ¯\(°_O)/¯
Posts: 3,373
![]() |
I'm dling VB right now since I don't have it installed on my laptop.
I'm gonna try something and just copy/paste the code here if it works cause I suck *** at explaining stuff. I'm not exactly the greatest at this right now though, come back and ask me in several years when I have my masters and I'll def be able to explain it to you though lol.
__________________
![]() All night I'll hunt for you Let me show you what I mean... |
|
|
|
|
|
#3 (permalink) |
|
Kohaku
Join Date: Feb 2008
Location: Mississauga, Ontario, Canada
Posts: 3,079
![]() |
Thanks.
See if you can get it before 10PM as then I have to sleep. We will be coding tomorrow so I don't want to do it my long way that I had originally planned. Which was, click the button it disappears and a new one appears with the new dialog and action. That way isn't the best. xD |
|
|
|
|
|
#6 (permalink) |
|
Raider of Empty Tombs
Join Date: May 2009
Location: USA. Unified Sarcastic Anal... something...
Posts: 357
![]() |
Code:
Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button.Click
If Button.Text = "Hello." Then
Label.Text = "Hi!"
Button.Text = "How are you?"
ElseIf Button.Text = "How are you?" Then
Label.Text = "I'm fine."
Button.Text = "I'm great!"
ElseIf Button.Text = "I'm great!" Then
Label.Text = "That's good to hear!"
Button.Dispose()
End If
End Sub
![]() Button.Dispose makes the button invisible after your conversation is over ^^ If you need any other help with VB.Net, feel free to ask.
__________________
|
|
|
|
|
|
#8 (permalink) |
|
Raider of Empty Tombs
Join Date: May 2009
Location: USA. Unified Sarcastic Anal... something...
Posts: 357
![]() |
I tested this personally and it worked perfectly, so I hope it does the same for you.
The problem with not using else is, after the first if is done, the sub checks the second if. Since the first if is done and changed the button name, the second if will continue without them clicking it again. Kinda confusing, I know. By using if, it only checks ONE of them per click, instead of doing one by one by one per click.
__________________
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|