views:

921

answers:

2

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: 
  1. Add an event handler to the button
  2. When the event is triggered:
  3. Read the text value in the text box
  4. Convert it to a number
  5. Increase the value of the number by one
  6. Put that number back to the textbox
  7. PROFIT :)
DrJokepu
This doesnt really do much for me, could you explain in terms of code?
Davey
Step 1: double click the button. VS creates the eventhandler for you. Continue with 3.
Henk Holterman
+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