Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
in a userform i am trying to add some fields together, but it concatenates
the fields together instead of adding them if textbox 1 is 10 and textbox2 is 5 me.textbox1.value + me.textbox2.value gives me 10 5 -me.textbox1.value*-1 + -me.textbox2.value*-1 gives me 15 multiplication works, too, just not addition anyone know why? -- Gary |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Hello Gary, Its one of those VBA oddities. It's a good practice not to rely on the system to decide what math function to perform on string data. Change your code to this and it will work fine regardless of what you do. N = Val(TextBox1.Value) + Val(TextBox2.Value) N will equal 15 TextBox.Value doesn't return a numeric value. It simply returns what is currrently diplayed by the TextBox. Sincerely, Leith Ross -- Leith Ross ------------------------------------------------------------------------ Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465 View this thread: http://www.excelforum.com/showthread...hreadid=484631 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
ok, thanks leith
-- Gary "Leith Ross" wrote in message ... Hello Gary, Its one of those VBA oddities. It's a good practice not to rely on the system to decide what math function to perform on string data. Change your code to this and it will work fine regardless of what you do. N = Val(TextBox1.Value) + Val(TextBox2.Value) N will equal 15 TextBox.Value doesn't return a numeric value. It simply returns what is currrently diplayed by the TextBox. Sincerely, Leith Ross -- Leith Ross ------------------------------------------------------------------------ Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465 View this thread: http://www.excelforum.com/showthread...hreadid=484631 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Actually it isn't an oddity. The plus sign was the original concatenation
operator. So if you + two strings, you get concatenation. Values in textboxes are strings even if they are numeric in nature. -- Regards, Tom Ogilvy "Leith Ross" wrote in message ... Hello Gary, Its one of those VBA oddities. It's a good practice not to rely on the system to decide what math function to perform on string data. Change your code to this and it will work fine regardless of what you do. N = Val(TextBox1.Value) + Val(TextBox2.Value) N will equal 15 TextBox.Value doesn't return a numeric value. It simply returns what is currrently diplayed by the TextBox. Sincerely, Leith Ross -- Leith Ross ------------------------------------------------------------------------ Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465 View this thread: http://www.excelforum.com/showthread...hreadid=484631 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Addition of Days | Excel Discussion (Misc queries) | |||
Addition? | Excel Discussion (Misc queries) | |||
addition | New Users to Excel | |||
row addition | Excel Worksheet Functions | |||
Userform addition question | Excel Programming |