ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Text Boxes (https://www.excelbanter.com/excel-programming/286014-text-boxes.html)

Jamal[_2_]

Text Boxes
 
I was following a question, which was posted to this group
about two weeks ago on summing up the values of text boxes
into another text box. I tried the following:

TextboxTotal = T1+T2+T3 'T being the textboxes

instead of adding the numerical values it just places them
side by side. So the contents of Textboxtotal becomes
100200300 instead of 600. However when i did the following
it works:

TextboxTotal = (T1*1)+(T2*1)+(T3*1)

it seems the contents of each box is not being treated as
numbers.

I am using Excel 2000

Is this a bug or I am missing something? Thanks. It is
just bugging me.


DennisE

Text Boxes
 
The contents of a textbox is just that, text. So when you write Total.ext =
TextBox1.text + TextBox2.text + TextBox3.text, Excel believes you are asking
for concatenation, just like "Apple" + "Pie" = "Apple Pie".
What you should be doing to get an arithmetic sum is writing Total.Value=
TextBox1.Value+TextBox2.Value+TextBox3.Value

-- Dennis Eisen

Jamal[_2_]

Text Boxes
 
Hi Dennis,

T1.value+t2.value concatenate the result. I have tried
with text and value. Same result. Anyway, thanks for your
interest and suggestion. Cheers.


-----Original Message-----
The contents of a textbox is just that, text. So when you

write Total.ext =
TextBox1.text + TextBox2.text + TextBox3.text, Excel

believes you are asking
for concatenation, just like "Apple" + "Pie" = "Apple

Pie".
What you should be doing to get an arithmetic sum is

writing Total.Value=
TextBox1.Value+TextBox2.Value+TextBox3.Value

-- Dennis Eisen
.


Jake Marx[_3_]

Text Boxes
 
Hi Jamal,

You can use conversion functions to convert the text strings into numeric
values. Here's an example that will work (assuming your "total" TextBox is
named "TextBox4"):

Private Sub CommandButton1_Click()
Dim dblTotal As Double
Dim ctl As Control

For Each ctl In Controls
If TypeOf ctl Is MSForms.TextBox Then
If ctl.Name < "TextBox4" Then
If IsNumeric(ctl.Object.Text) Then
dblTotal = dblTotal + _
CDbl(ctl.Object.Text)
End If
End If
End If
Next ctl

TextBox4.Text = Format$(dblTotal, "#,##0.00")
End Sub


This will add up all values in TextBoxes on the Userform. It ignores
non-numeric values.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


Jamal wrote:
I was following a question, which was posted to this group
about two weeks ago on summing up the values of text boxes
into another text box. I tried the following:

TextboxTotal = T1+T2+T3 'T being the textboxes

instead of adding the numerical values it just places them
side by side. So the contents of Textboxtotal becomes
100200300 instead of 600. However when i did the following
it works:

TextboxTotal = (T1*1)+(T2*1)+(T3*1)

it seems the contents of each box is not being treated as
numbers.

I am using Excel 2000

Is this a bug or I am missing something? Thanks. It is
just bugging me.




All times are GMT +1. The time now is 06:41 PM.

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