CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2001
    Location
    Chicago, IL
    Posts
    27

    Visual Basic Help

    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

  2. #2
    Join Date
    Apr 2001
    Location
    Salt Lake City, UT
    Posts
    135

    Re: Visual Basic Help

    Do you have a sample of your code? That may help determine why it isn't working.

    "There are no stupid questions, but there are a lot of inquisitive idiots."

  3. #3
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: Visual Basic Help

    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





  4. #4
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Visual Basic Help

    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
    [email protected]
    Iouri Boutchkine
    [email protected]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured