Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 . |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|