I'm stuck on this exercise that asks me to create a text box and a button. Each time the button is pressed it is supposed to add 1 to the text box. Anyone know how to approach this?
+1
A:
- Add an event handler to the button
- When the event is triggered:
- Read the text value in the text box
- Convert it to a number
- Increase the value of the number by one
- Put that number back to the textbox
- PROFIT :)
DrJokepu
2009-02-22 23:43:46
This doesnt really do much for me, could you explain in terms of code?
Davey
2009-02-22 23:54:45
Step 1: double click the button. VS creates the eventhandler for you. Continue with 3.
Henk Holterman
2009-02-23 00:15:42
+3
A:
Public Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim i as Integer = int.Parse(TextBox1.Text)
i += 1
TextBox1.Text = i.ToString()
End Sub
You will also want to protect any attempt to key press in the textbox or set it where Enabled=true.
Gregory A Beamer
2009-02-23 00:20:18