VB question

Mean MrMustard

Diamond Member
Jan 5, 2001
3,144
10
81
I have to access a sequential file that has to fields in it separated by a comma (obviously). The first field is placed in the combo box at Form Load time. I have that done. How ever when I click on an item in the combo box I need the information from the second field that corresponds with the item chosen.

Private Sub cbo1_Click()
Open AppPath & FileName For Input As 1

Input #1, mstrMeal
Input #1, msngPrice(4)
lblUnitP1.Caption = msngPrice(cbo1.ListIndex + 1)
txtQuantity1.Text = 1

Close 1
End Sub

I need it so that when you choose a meal in the combo box the price (second field) shows up in the lblUnitP1.caption.

Am I correct in setting up an array with msngPrice(4)?
 

nboy22

Diamond Member
Jul 18, 2002
3,304
1
81
Ok, this was the hard part for me until I bought a $40 book from Barnes and Noble!

ok, first of all you want.

Private Sub cbo1_Click()
Open AppPath & FileName For Input As 1

Input #1, mstrMeal
Input #1, msngPrice(4)
txt Quantity1.Text = 1

Close 1
End Sub

So then under your Private Sub lblUnitP1.caption, it should look like this

Private Sub lblUnitP1_caption - i don't know if that is really it but it should look similar!
Select Case cbo1.ListIndex

Case 0
lblUnitP1.caption = "whatever you want to be for the first selection" - in your case i think you want mstrMeal for the selection, but i'm not sure!
- then just complete the other ones with things that look like this

Case 1
lblUnitP1.caption = "whatever you want"

Case 2
lblUnitP1.caption = "whatever you want"

Case 3
lblUnitP1.caption = "whatever you want"


NOTE!!!!!!!!!!!: IF THIS DOES NOT WORK WITH A COMBO BOX TRY USING A LIST BOX INSTEAD AND IT SHOULD WORK FINE IF IT DIDN'T WITH A COMBO BOX!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!




 

Mean MrMustard

Diamond Member
Jan 5, 2001
3,144
10
81
Thanks.

The case didn't work and I have to use a combo box.
I thought there was a way to access the prices from the file itself. How come I can access the first field(Form Load) but not the second?
 

nboy22

Diamond Member
Jul 18, 2002
3,304
1
81
yeah, you just have to tweak it if it doesn't work and you'll get it sooner or later.