Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Numeric Textboxes

Status
Not open for further replies.

rahulpatel

Programmer
Jan 20, 2007
33
AU
Don't you just hate it when the simplest things seem the most difficult objects.

I have 2 textboxes on my form. I want to add 5 to the second textbox when a certain value is first textbox. eg

Code:
    Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged


        If TextBox1.Text = "123456" Then
            TextBox2.Text = " " + 5

        End If
    End Sub

However this doesn't work obviously. How do I do it??

 
rahul, well obviously you can't add anything to a null value so you will have to check for that first:

Code:
if not TextBox2.Text is nothing then
cInt(textbox2.text) += 5
else
textbox2.text = 5
end if

Use cInt to convert the text value from the textbox to a type integer.

Cheers

Nick
 
Not sure what result you are trying to achieve if the TextBox1.Text = "123456"

In addition to what nickdel has pointed:

1. "1234565"
Code:
If TextBox1.Text = "123456" Then
    TextBox2.Text = TextBox1.Text & "5"
End If
2. 123461
Code:
If Val(TextBox1.Text) = 123456 Then
    TextBox2.Text = Val(TextBox1.Text) + 5
End If

Regards.
 
Thanks both. I realised you have to make it an integer.

Mansii, 123456 was just an example. It's going to be used for a very simple inventory prog. Basically when a certain number is barcoded into a textbox it will add or subtract a specific value from a quantity field in the db which will then be shown in a textbox. (Of course I say simple but in my mind by the end it's going to be a fully fledged, all singing, all dancing, fully automated stock inventory programme worth millions.!!!)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top