ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   userform addition (https://www.excelbanter.com/excel-programming/345467-userform-addition.html)

Gary Keramidas

userform addition
 
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




Leith Ross[_269_]

userform addition
 

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


Gary Keramidas

userform addition
 
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




Tom Ogilvy

userform addition
 
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





All times are GMT +1. The time now is 12:00 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com