Results 1 to 9 of 9

Thread: [RESOLVED] Problem with multiple list boxes.

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2008
    Posts
    9

    Resolved [RESOLVED] Problem with multiple list boxes.

    Hello,
    I have received a VB assignment in which I must transfer data from one list box to another. While I can get it to transfer the items one by one, it is a requirement that you can enter a quantity of items to add, eg. 2 bricks - I cannot get it to add more than 1 of the same item without clicking the button multiple times, let alone the quantity desired. Any help with the code/ideas in general would be much appreciated.
    the items must also display a price. Would it be easiest to put the price in the same listbox or a separate listbox?
    Thanks,
    Strongbee

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Problem with multiple list boxes.

    Welcome to the forums.

    So, if you have 2 bricks you want it to add the word bricks twice?

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2008
    Posts
    9

    Re: Problem with multiple list boxes.

    Thankyou.
    Yeah, that's right - click on the item, type the number you want of that item in a text box, press the add button, and the word is added that many times. - click bricks, type 2, bricks comes up twice - just as you said

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Problem with multiple list boxes.

    You use a For loop, going from 1 to the number you typed in. Inside the loop you add the item from the first ListBox to the second. If your For loop goes from 1 to 5 then you'll add the item 5 times.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    New Member
    Join Date
    Mar 2008
    Posts
    2

    Re: Problem with multiple list boxes.

    Hiho,

    you can do this with a loop

    Here's a little example. (The Methods to add an item maybe depend on your VB Version)

    vb Code:
    1. Sub AddIt()
    2.  
    3.     For Index = 0 To Me.MyTextBox.Value
    4.         Me.MyTargetListbox.Item.Add (Me.MySourceListbox.Text)
    5.     Next
    6.    
    7. End Sub
    Last edited by Tandriin; Mar 26th, 2008 at 07:41 AM.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Problem with multiple list boxes.

    Quote Originally Posted by Tandriin
    Hiho,

    you can do this with a loop

    Here's a little example. (The Methods to add an item maybe depend on your VB Version)

    vb Code:
    1. Sub AddIt()
    2.  
    3.     For Index = 0 To Me.MyTextBox.Value
    4.         Me.MyTargetListbox.Item.Add (Me.MySourceListbox.Text)
    5.     Next
    6.    
    7. End Sub
    People should generally write their own code for assignments. Also, TextBoxes have no Value property.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    New Member
    Join Date
    Mar 2008
    Posts
    9

    Re: Problem with multiple list boxes.

    Ahh, thankyou all for the suggestions. Unfortunately, I cannot apply these suggestions until tomorrow, as I can only access VB at my school, and we are off today. I shall respond as soon as I get results however!

  8. #8
    Fanatic Member Clanguage's Avatar
    Join Date
    Jan 2008
    Location
    North Carolina
    Posts
    659

    Re: Problem with multiple list boxes.

    Quote Originally Posted by Tandriin

    vb Code:
    1. Sub AddIt()
    2.  
    3.     For Index = 0 To Me.MyTextBox.Value
    4.         Me.MyTargetListbox.Item.Add (Me.MySourceListbox.Text)
    5.     Next
    6.    
    7. End Sub
    Actually I think that you will get an out of bound error on this example.
    CLanguage;
    IF Post = HelpFull Then
    RateMe
    Else
    Say("Shut UP")
    End If
    DotNet rocks
    VB 6, VB.Net 2003, 2005, 2008, 2010, SQL 2005, WM 5.0,ahem ?OpenRoad?

  9. #9

    Thread Starter
    New Member
    Join Date
    Mar 2008
    Posts
    9

    Re: Problem with multiple list boxes.

    huzzah!
    I just thought I'd let everyone know that the for loop idea worked perfectly - I managed to create myself a working quantity generator.
    Thanks everyone for your help.

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