Excel VBA

S

Sheela

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
 
A

Arne

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top