PDA

View Full Version : Solved: Syntax calculation error



bopo
01-13-2007, 05:51 PM
Hi people


Basically I want to add the values of two textboxes together, and then multiply that value via a number in a different textbox

here is similar code to mine



txttotalcost.Text = txtcost1 + txtcost2 * people


however, assume the following

txtcost1 = 10
txtcost2 = 10
people = 2

the obvious answer is 40, however it comes up with 30, its the same for all types of numbers.

mdmackillop
01-13-2007, 06:18 PM
Add .Value as in
Label1.Caption = TextBox1.Value * TextBox2.Value * TextBox3.Value

Bob Phillips
01-13-2007, 06:20 PM
txttotalcost.Text = (txtcost1 + txtcost2) * people

bopo
01-13-2007, 06:53 PM
Thanks for help however using the above senario:

' txtcost1 = 10
txtcost2 = 10
people = 2'

I am getting a result of 200 using both methods, anu ideas?

gnod
01-13-2007, 07:10 PM
use the code from xld. you need to use parenthesis in order to override the rules of precedence of operators..

bopo
01-14-2007, 03:34 AM
Well using that, I am getting 1010 any help?


edit: I kind of resolved this using a little cheat, but I want it to display to two decimal values such as 10.00, any ideas?

Bob Phillips
01-14-2007, 04:33 AM
txttotalcost.Text = Format((Val(txtcost1.Text) + Val(txtcost2.Text)) * people,"#,##0.00")

bopo
01-14-2007, 05:37 AM
Works perfectly, thanks :D