ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel VBA (https://www.excelbanter.com/excel-programming/272523-excel-vba.html)

sheela

Excel VBA
 
Hello,

I have a problem. When I try total up values fom a list
of textboxes using the formula as below, it actually
combine the values from all the textboxes.
__________________________________________________ _______
txtFinalBill.Text = Val(txtCalculatedDemandCharge.Text) +
Val(txtEmp.Text) + Val(txtEmop.Text) + Val
(txtFirmStandbyCharge.Text) + Val
(txtNonFirmStandbyCharge.Text) + Val
(txtPowerFactorPenalty.Text) + Val(TextBox25.Text)
__________________________________________________ ________

Has it got its limitation in totalling up the values?

Thanks,

Sheela

Arne[_2_]

Excel VBA
 
It is strange to assign a numeric value to a string
(textbox.text is of type string). On the other hand, the
textbox also has a property called 'value' which will
return a variant, and which will, in principle need no
explicit conversions.

The problem with adding the variants textbox.value of all
textboxes is, that it will add the strings instead of the
numbers. So first, tell VBA what kind of addition is
required, and then actually carry it out:

Dim dblTmp As Double
dblTmp = TextBox1.Value
TextBox5.Value = dblTmp + TextBox2.Value + TextBox3.Value
+ TextBox4.Value

Agreed, you need one extra temporary variable, but you do
not have any conversions

-----Original Message-----
Hello,

I have a problem. When I try total up values fom a list
of textboxes using the formula as below, it actually
combine the values from all the textboxes.
_________________________________________________ ________
txtFinalBill.Text = Val(txtCalculatedDemandCharge.Text) +
Val(txtEmp.Text) + Val(txtEmop.Text) + Val
(txtFirmStandbyCharge.Text) + Val
(txtNonFirmStandbyCharge.Text) + Val
(txtPowerFactorPenalty.Text) + Val(TextBox25.Text)
_________________________________________________ _________

Has it got its limitation in totalling up the values?

Thanks,

Sheela
.



All times are GMT +1. The time now is 05:13 PM.

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