Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Adding numbers and text | Excel Discussion (Misc queries) | |||
Comparing text and then adding numbers if the text matches | Excel Worksheet Functions | |||
Adding numbers to text! | Excel Worksheet Functions | |||
adding cells with text and numbers | Excel Discussion (Misc queries) | |||
Adding cells with numbers and text | Excel Worksheet Functions |