what i have is a userform with a combo box, cmbSelectIngredient, and two
text boxes, txtIngredientName and txtAmount. in the DropButtonClick
event of the combo box i have this code:
Code:
--------------------
Private asIngredientNames(24) As String
Private adIngredientAmounts(24) As Single
Private Sub cmbSelectIngredient_DropButtonClick()
If txtIngredientName.Text = "" Then
Exit Sub
Else
asIngredientNames(cmbSelectIngredient.ListIndex) = CStr(txtIngredientName.Text)
End If
If txtAmount.Text = "" Then
adIngredientAmounts(cmbSelectIngredient.ListIndex) = 0
Else
adIngredientAmounts(cmbSelectIngredient.ListIndex) = CSng(txtAmount.Text)
End If
cmbSelectIngredient.AddItem "Ingredient " & cmbSelectIngredient.ListIndex + 1
End Sub
--------------------
and in the Change event i have this code:
Code:
--------------------
Private Sub cmbSelectIngredient_Change()
If asIngredientNames(cmbSelectIngredient.ListIndex) < "" Then
If adIngredientAmounts(cmbSelectIngredient.ListIndex) = 0 Then
GoTo Skip
Else
txtAmount.Text = adIngredientAmounts(cmbSelectIngredient.ListIndex)
End If
txtIngredientName.Text = asIngredientNames(cmbSelectIngredient.ListIndex)
End If
Skip:
txtIngredientName.Text = ""
txtAmount.Text = ""
End Sub
--------------------
and this as initialization:
Code:
--------------------
Private Sub UserForm_Initialize()
cmbSelectIngredient.AddItem "Ingredient " & 1
cmbSelectIngredient.ListIndex = 0
End Sub
--------------------
basically, what i try to achieve with this code is storing a string and
a single into thier corresponding arrays, then when a previously stored
ingredient is selected, i would like to fill the textboxes with the
information previously stored in the array. but i'm getting all sorts
of problems. mainly because i can't figure out how to recall the
values into the textboxes. my code seems like it would do it, but
since the ListIndex isn't changed until after the Change event it
called, i think it may be impossible to do because i can't predict
which line the user will select. maybe there's some way of finding out
which line is selected before the Change event is called?
--
medicenpringles
------------------------------------------------------------------------
medicenpringles's Profile:
http://www.excelforum.com/member.php...o&userid=16458
View this thread:
http://www.excelforum.com/showthread...hreadid=492920