Click to See Complete Forum and Search --> : Visual Basic Help
Archie
April 13th, 2001, 11:11 AM
Hi all - I am a programming rookie and am having some trouble with a program. For the program, I'm supposed to read a grocery list from a text file into a listbox. Then, I'm supposed to create another list box. This second list box will be populated by me clicking on items in the first list box and then clicking on a command button that will add all the items I selected. It's supposed to work even if there's more than one item selected. Any help would be greatly appreciated. Thanks.
Archie Kantzavelos
goddess_spanky
April 13th, 2001, 11:23 AM
Do you have a sample of your code? That may help determine why it isn't working.
shree
April 13th, 2001, 11:41 AM
Here's the code for you.
private Sub cmdAdd_Click()
Dim i as Integer
for i = 0 to List1.ListCount - 1
If List1.Selected(i) then
List2.AddItem List1.List(i)
End If
next
End Sub
private Sub Form_Load()
Dim aLine as string
Open App.Path & "\grocery.txt" for input as #1
Do While Not EOF(1)
Line input #1, aLine
List1.AddItem aLine
Loop
Close #1
End Sub
Iouri
April 13th, 2001, 01:47 PM
change the line in your code
If List1.Selected(i) then
List2.AddItem List1.List(i)
to the following
If List1.Selected(i) = True Then
List2.AddItem List1.List(i)
Iouri Boutchkine
iouri@hotsheet.com
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.