I am writing a little program (calculator) in which I have a combo box with materials and their values. Such as: Glass 1.80 or LH67 1.79. My problem is that I don't know how to pick something in the drop down box and only have the numeric values enter into the equation. I get an error every time because the words (glass or LH67) are being picked as well.
Solvation :
Depending on when you want to collect the data, you could use something like below.
This is based on clicking a button once you have made your selection, but should be easy enough for you to add to the combobox event if necessary.
1: Private Sub Command1_Click()
2: Dim astrdata() As String
3: astrdata = Split(Combo1.Text, " ")
4: MsgBox "Value of " & astrdata(0) & " is : " & astrdata(1)
5: End Sub
Just to note that the data is extracted as a string.
If you want to do calculations with it, you will need to validate and cast it as the relevant numeric type.
Hope that helps.
Post a Comment