Summing Textbox values in a Form


Posted by Anna Daly on November 19, 2000 9:09 AM

Hello All,

I have a form that contains several textboxes. The textboxes are for the user to input numeric values. In an output textbox (on the same form) the sum of all the input textboxes needs to be displayed. This sounds simple and the code that I have used is the following:

Textbox1.value = textbox2.value + textbox3.value + ....

It runs okay but gives the wrong answear. eg if textbox2.value =1000 and textbox3.value =2000
it displays textbox1.value=10002000 when it should be 3000. I know what it is doing, its adding the values as strigs instead of integers.

I don't know how to solve it. Any ideas?

regards

Anna Daly



Posted by Tim Francis-Wright on November 20, 2000 2:53 PM


It's not a bug, it's a feature!

Use the Val() function to convert the (string) value of each textbox to a number:

TextBox4.Value = Val(TextBox1.Value) + Val(TextBox2.Value) + Val(TextBox3.Value)

Good Luck!