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

Adding values in textboxes 2

Status
Not open for further replies.

missmarci

Programmer
Jun 25, 2002
16
US
I am VERY new at this, but am trying to do something as simple as adding the values of two text boxes but instead of adding it smushes the numbers together (concantanation) so if txtMatTotal.text is 12 and txtPadPriceTotal.text is 10, txtTax.text ends up being 1210 instead of 22. If i substitute subtraction or multiplication or division, it works. The first two lines work beautifully. Please help. This answer is probably so easy, but I just can't seem to get it. Thank you.

Private Sub Command1_Click()

txtPadPriceTotal.Text = txtPadPriceSF.Text * txtSF.Text
txtMatTot.Text = txtPriceSF.Text * txtSF.Text
txtTax.Text = (txtMatTot.Text) + (txtPadPriceTotal.Text)

End Sub
 
Use the Val() function:

txtPadPriceTotal.Text = Val(txtPadPriceSF.Text) * Val(txtSF.Text)
txtMatTot.Text = Val(txtPriceSF.Text) * Val(txtSF.Text)
txtTax.Text = Val(txtMatTot.Text) + Val(txtPadPriceTotal.Text)
 
The problem is that you are trying to do math on string and not numbers. Even '12' in a text box is a string even though it looks like a number. Try this

txtTax.Text = val(txtMatTot.Text) + val(txtPadPriceTotal.Text)
Thanks and Good Luck!

zemp
 
txtTax.Text = (txtMatTot.Text) + (txtPadPriceTotal.Text)

The "+" symbol is the old concatenation symbol (now replaced by "&"). Try this to add the contents of the 2 text boxes - the Val command converts to numbers:

txtTax.Text = Val(txtMatTot.Text) + Val(txtPadPriceTotal.Text)

 
I think you need to use val like this:

txtTax.Text = val(txtMatTot.Text) + val(txtPadPriceTotal.Text
 
You could also look at the CLng(), CInt(), CDbl(), and CDec() procedures. If you choose to battle wits with the witless be prepared to lose.
[machinegun][ducky]
 
Thank you all!! Worked great and now my family thinks i'm human again!! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top