Reputation: 1
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
Upvotes: 0
Views: 2043
Reputation: 19367
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(?).
Upvotes: 0