Tim Francis Wright - More Help Please


Posted by Anna Daly on November 21, 2000 10:45 AM

Hi Tim

Thanks for your help you gave on summing integer values in textboxes. You suggested that I used:

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

This does work but there is a problem with the number formats. The textboxes that I am summing have been assigned the number format of #,##0. I think that when I am using the method that you suggested it thinks the comma is a decimal place and therefore gives the wrong answear. eg

if textbox2.value =8,000 and textbox3.value = 1
it gives textbox1.value = 9
when it should be = 8,001

any ideas on how to overcome this little problem?

Kind regards

Anna Daly

Posted by Anna Daly on November 21, 2000 10:49 AM

Sorry, it should read TB1.Value = TB2.Value + TB3.Value




Posted by Tim Francis-Wright on November 21, 2000 11:23 AM

The following is ugly, but it will work. (Perhaps someone would be kind enough to suggest
a more elegant solution.)

TextBox3.Value = Format(Val(Format(TextBox1.Value, "0")) + Val(Format(TextBox2.Value, "0")), "#,##0")

The problem is that the Val function doesn't know that commas act as thousand separators.
The workaround passes to Val the strings without commas, then puts commas into the sum.

HTH