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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Math question between two textfields

Status
Not open for further replies.

GaryWilsonCPA

Technical User
Jul 19, 2000
253
US

I wish to use two fields to create an amount in a third field. Edit amount should be the sum of textbo2 times editquatity. If I put the formula together like below I get a concactonation of editquantity and textbox2.

editAmount.Text = (editQuantity.Text) + (TextBox2.Text)

I think I am on the right path, but I need to change the formula to below, I get errors.

editAmount.Text = (editQuantity.Text) * (TextBox2.Text)

I think my problem is that I am dealing with text vs numbers and need to understand how to change the text to a number and then do my formula.

Can anyone point me in the correct direction.



 
+ is an overloaded operator in VB which means that it does different things depending on the data types of its arguments. In your case your arguments are "text" so the "+" operation is to concatenate them. To get "+" to do an arithemetic add you need to convert the arguments to numbers
Code:
editAmount.Text = Val(editQuantity.Text) + Val(TextBox2.Text)
Properly, you should check that your text boxes contain text strings that can be converted to numbers. Look at the "IsNumeric" function for that.
 
Thanks for the information. It helped

I also discovered that by not having the text boxes bound to dataset fixed was a problem. I then followed up with two new text boxes that had the following code.

textboxnew1.text = editQuantity.Text
textboxnew2.text = TextBox2.Text

this picked up the amounts placed in the two previous text boxes and saved them to my table.

Both of these new fields are bound to a dataset that gets updated. Therefore those two fields get saved.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top