[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
Re: Problem with multiple list boxes.
Welcome to the forums. :wave:
So, if you have 2 bricks you want it to add the word bricks twice?
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
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.
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:
Sub AddIt()
For Index = 0 To Me.MyTextBox.Value
Me.MyTargetListbox.Item.Add (Me.MySourceListbox.Text)
Next
End Sub
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:
Sub AddIt()
For Index = 0 To Me.MyTextBox.Value
Me.MyTargetListbox.Item.Add (Me.MySourceListbox.Text)
Next
End Sub
People should generally write their own code for assignments. Also, TextBoxes have no Value property.
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!
Re: Problem with multiple list boxes.
Quote:
Originally Posted by Tandriin
vb Code:
Sub AddIt()
For Index = 0 To Me.MyTextBox.Value
Me.MyTargetListbox.Item.Add (Me.MySourceListbox.Text)
Next
End Sub
Actually I think that you will get an out of bound error on this example.;)
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.:)