Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Adding numbers in text box

I have a form with 3 text boxes. I want to add the values
in each to get a total and show the total in a label. I'm
using this code:
Total = txtHouseCost.Value + txtLotCost.Value +
txtOptionCost.Value
lblTotalNum = Total
If I enter a 1, a 2 and a 3 in each box I get 123 not 6.
It looks like I am concattinating, not summing.
What have I missed?
Thanks for the help!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 618
Default Adding numbers in text box

Hi Doug

By default textboxes entries are treated as "text" - so you need to coerce
the results to a number

using one of the following functions
Total = CINT(txtHouseCost.Value) + CINT(txtLotCost.Value) +
CINT(txtOptionCost.Value)

or
Total = CDBL(txtHouseCost.Value) + CDBL(txtLotCost.Value) +
CDBL(txtOptionCost.Value)

or
Total = val(txtHouseCost.Value) + val(txtLotCost.Value) +
val(txtOptionCost.Value)

or even
Total = --(txtHouseCost.Value) + --(txtLotCost.Value)
+ --(txtOptionCost.Value)


Cheers
JulieD


"Doug Loewen" wrote in message
...
I have a form with 3 text boxes. I want to add the values
in each to get a total and show the total in a label. I'm
using this code:
Total = txtHouseCost.Value + txtLotCost.Value +
txtOptionCost.Value
lblTotalNum = Total
If I enter a 1, a 2 and a 3 in each box I get 123 not 6.
It looks like I am concattinating, not summing.
What have I missed?
Thanks for the help!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Adding numbers in text box

Interestingly, it doesn't seem to be necessary to coerce all of the textbox
values, just one seems to do. So

CInt(txtHouseCost.Text) + txtLotCost.Text + txtOptionCost.Text

works. I don't think I would personally recommend it, I wouldn't like to
rely on this 'fetaure' always working, but it is interesting.

You can also use +0 or *1 as operators. Probably best to avoid Cint or CLng
for flexibility.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"JulieD" wrote in message
...
Hi Doug

By default textboxes entries are treated as "text" - so you need to coerce
the results to a number

using one of the following functions
Total = CINT(txtHouseCost.Value) + CINT(txtLotCost.Value) +
CINT(txtOptionCost.Value)

or
Total = CDBL(txtHouseCost.Value) + CDBL(txtLotCost.Value) +
CDBL(txtOptionCost.Value)

or
Total = val(txtHouseCost.Value) + val(txtLotCost.Value) +
val(txtOptionCost.Value)

or even
Total = --(txtHouseCost.Value) + --(txtLotCost.Value)
+ --(txtOptionCost.Value)


Cheers
JulieD


"Doug Loewen" wrote in message
...
I have a form with 3 text boxes. I want to add the values
in each to get a total and show the total in a label. I'm
using this code:
Total = txtHouseCost.Value + txtLotCost.Value +
txtOptionCost.Value
lblTotalNum = Total
If I enter a 1, a 2 and a 3 in each box I get 123 not 6.
It looks like I am concattinating, not summing.
What have I missed?
Thanks for the help!





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
Adding numbers and text Bluesquid619B Excel Discussion (Misc queries) 4 June 12th 09 10:38 PM
Comparing text and then adding numbers if the text matches rotor11 Excel Worksheet Functions 2 April 8th 09 08:38 PM
Adding numbers to text! Rocketeer Excel Worksheet Functions 4 May 12th 08 01:57 PM
adding cells with text and numbers Tat Excel Discussion (Misc queries) 1 June 22nd 05 03:01 AM
Adding cells with numbers and text EddieZ Excel Worksheet Functions 4 November 9th 04 12:43 PM


All times are GMT +1. The time now is 10:18 AM.

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"