0

i have a userform that includes combox and two textboxes the user choose a chemical (text) from the combobox1 and enters the height of the chemical in textbox1 (number). then according to the chemical he choose i define the density and area of the tank of the chemical. then i need to calculate: textbox2.value=density*area*textbox1.value density and area are different for every chemical. the equation is mass=density*area*volume. i tried this code: Private Sub ComboBox1_Change() Dim chem As String

chem = ComboBox1.Value
    mychem

End Sub
Sub mychem()
Dim density As Double
Dim volume As Double

If chem = "Sodium" Then
area = 22
density = 1.058
End If
If chem = "HCl 9%" Then
area = 22
density = 1.043
End If
If chem = "alum" Then
area = 70
density = 1.163
End If
If IsNumeric(Txtheight.Text) Then
                txtmass.Value = density *area * CDbl   (Txtheight.Value)

                   End If
end sub

1 Answer 1

0

density and volume are variables, they don't have a Value property.

TextBox4.Value = CDbl(density) * CDbl(volume) * CDbl(TextBox8.Value)

Also, density and volume are already Doubles, you don't need to convert them with CDbl.

And you should take the time to rename your controls. I would suggest txtHeight but your description isn't clear about whether the textbox contains the height, area or volume(?).

Sign up to request clarification or add additional context in comments.

1 Comment

thanks, now the calculation works with no bug. but it gives answer 0. i'm guessing that the code doesnt define my variables currectly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.