Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default 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



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default 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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Addition of Days Ricky Excel Discussion (Misc queries) 3 January 27th 09 09:13 AM
Addition? Frodo Excel Discussion (Misc queries) 3 July 22nd 06 01:15 PM
addition dali New Users to Excel 1 March 4th 06 06:40 PM
row addition Threshold Excel Worksheet Functions 3 March 17th 05 08:08 PM
Userform addition question Patrick Simonds Excel Programming 3 May 22nd 04 04:20 PM


All times are GMT +1. The time now is 07:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"