|
-
Mar 26th, 2008, 07:11 AM
#1
Thread Starter
New Member
[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
-
Mar 26th, 2008, 07:19 AM
#2
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?
-
Mar 26th, 2008, 07:21 AM
#3
Thread Starter
New Member
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
-
Mar 26th, 2008, 07:34 AM
#4
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.
-
Mar 26th, 2008, 07:38 AM
#5
New Member
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
Last edited by Tandriin; Mar 26th, 2008 at 07:41 AM.
-
Mar 26th, 2008, 07:49 AM
#6
Re: Problem with multiple list boxes.
 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.
-
Mar 26th, 2008, 03:45 PM
#7
Thread Starter
New Member
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!
-
Mar 26th, 2008, 03:54 PM
#8
Fanatic Member
Re: Problem with multiple list boxes.
 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.
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?
-
Mar 28th, 2008, 12:08 AM
#9
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|