add a value to a textbox by clicking a button?

Starfleeter

Member
Joined
Oct 31, 2010
Messages
5
Programming Experience
Beginner
EDIT: Oops, sorry, this post should probably go in the VB.net forum but I can't find a way to delete it.

So I'm brand spanking new and trying to learn VB.net on my own but am doing a horrible job. It seems I can follow basic tutorial instructions and do them correctly but not learn how to do things on my own.

Anyway, I'm trying to do simple stuff first like have a textbox and a button that I click that adds 1 to the value in the textbox and makes the textbox output that value but I can't get it to work for the life of me. I know it's probably something really easy but yeah, I just can't figure it out after scouring the net now for about 45 minutes.

VB.NET:
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtStrength.TextChanged
        txtStrength.Text = 5
    End Sub

    Private Sub btnStrengthPlus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStrengthPlus.Click
        Dim c As Integer
        c = Val(txtStrength.Text) + 1
        txtStrength.Text = c
    End Sub
 
Get rid of the TextChanged event handler. That will detect every time the Text of the TextBox changes and then change the Text to "5", so you'll never be able to change it from "5". The rest of the code is not optimal but will do the job you want as is.
 
Thanks a bunch, I realize what was going on now. Every time I clicked anything on the design page, it was opening up a code snippet even if I didn't need to use it at all but since I'm not familiar with programming/vb.net I didn't recognize it as something I needed to get rid of. I'm being a lot more careful with what I click and deleting anything that I don't actually need code run on now.

Thanks.
 
Back
Top