473,324 Members | 2,581 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

For each loop for listbox items?

Hi,
I'm trying to do a batch process for all the items in my listbox1
using "for each...next" ? I'm not well-experienced on this yet, how
can i sample this?

For example: From item1 to last item (there's no guess for how many
items a user can add as well),
I want my external process run one by one. Process must run for item1
then item2 when item1's work finishes....until the last listbox item.

How can i do that?
Thanks.

Nov 10 '07 #1
5 13307
On Nov 10, 8:31 am, kimiraikkonen <kimiraikkone...@gmail.comwrote:
Hi,
I'm trying to do a batch process for all the items in my listbox1
using "for each...next" ? I'm not well-experienced on this yet, how
can i sample this?

For example: From item1 to last item (there's no guess for how many
items a user can add as well),
I want my external process run one by one. Process must run for item1
then item2 when item1's work finishes....until the last listbox item.

How can i do that?

Thanks.
A for each/next will work as long as you don't tend to actually add or
remove items from the list. Otherwise, you'll have to do a normal for
loop (though, you'll need to go backwards to avoid errors).

Anway here is a for each loop:

For Each item As MyItemType In MyComboBox.Items
' do cool stuff with item
Next

HTH

--
Tom Shelton

Nov 10 '07 #2

"kimiraikkonen" <ki*************@gmail.comwrote in message
news:11*********************@v2g2000hsf.googlegrou ps.com...
Hi,
I'm trying to do a batch process for all the items in my listbox1
using "for each...next" ? I'm not well-experienced on this yet, how
can i sample this?

For example: From item1 to last item (there's no guess for how many
items a user can add as well),
I want my external process run one by one. Process must run for item1
then item2 when item1's work finishes....until the last listbox item.

How can i do that?
Thanks.
Each item in the listbox is an object and uses the tostring property to
display the item.

So you would do the following:

for each li as (your object type or string if you stored them that way) in
listbox1.items

' within the loop you will process each item.
' lets say you store the execute path of the process you want to start
so li would be a string

dim yourProcess as Process
yourProcess = Process.Start(li)
yourProcess.WaitForExit()

next

Has no error checking but I would not want you to lose out on some of the
fun.

Hope this helps
Lloyd Sheen

Nov 10 '07 #3
None of them worked :(

i got error for "next" saying:

"List that this enumerator is bound to has been modified. An
enumerator can only be used if the list does not change."

OK, i wanna rewind it, forget external process, let's go with
simple :)

Think a listbox1 has about 10 items (with different names, bla-bla-
bla...),
When i press button1, i want "each" item to be selected one by one for
all the items in the list, meanwhile the selected item's value must be
displayed in messagebox (e.g. msgbox(listbox1.selecteditem) )

Which proper loop function/syntax can i do with?

Very thanks...

Nov 10 '07 #4
I'm afraid and apologize, None of them worked or i couldn't do :(

i got error for "next" saying:

"List that this enumerator is bound to has been modified. An
enumerator can only be used if the list does not change."

OK, i wanna rewind it, forget external process, let's go with
simple :)

Think a listbox1 has about 10 items (with different names, bla-bla-
bla...),
When i press button1, i want "each" item to be selected one by one for
all the items in the list using Me.ListBox1.SelectedIndex =
Me.ListBox1.SelectedIndex + 1,
meanwhile the selected item's value must be
displayed in messagebox (e.g. msgbox(listbox1.selecteditem) )

Which proper loop function/syntax can i do with?

Very thanks...

Nov 10 '07 #5

"kimiraikkonen" <ki*************@gmail.comwrote in message
news:11**********************@57g2000hsv.googlegro ups.com...
I'm afraid and apologize, None of them worked or i couldn't do :(

i got error for "next" saying:

"List that this enumerator is bound to has been modified. An
enumerator can only be used if the list does not change."

OK, i wanna rewind it, forget external process, let's go with
simple :)

Think a listbox1 has about 10 items (with different names, bla-bla-
bla...),
When i press button1, i want "each" item to be selected one by one for
all the items in the list using Me.ListBox1.SelectedIndex =
Me.ListBox1.SelectedIndex + 1,
meanwhile the selected item's value must be
displayed in messagebox (e.g. msgbox(listbox1.selecteditem) )

Which proper loop function/syntax can i do with?

Very thanks...
If you remove an item from the list while in a for each loop you will get
that message. If you are processing all the items you can clear the listbox
after all the items are processed or do the following:

for i as integer = 0 to listbox1.items.count-1

next

LS

Nov 10 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Valerian John | last post by:
I have a ListBox webcontrol on an aspx page. Items are added to the ListBox using client-side code. However, when the page is posted back the items are missing/not available. (It is like the...
3
by: Stimp | last post by:
I have a listbox of values that I populate from a database. I want the user to be able to re-order the list (by first selecting an item and then clicking 'up' or 'down' buttons) and then save...
3
by: Baren | last post by:
Hi! I have a generalized Stored Procedure to get the listbox items in a datareader.Then i am binding the datareader to the listbox. For different pages and different conditions i need to hide...
0
by: marcelo | last post by:
Could you help me out here. I need to accomplish this: I need to filter listbox items from by entering some characters to the textbox. But the problem is that items (files that are read from...
3
by: Brian Simmons | last post by:
Hi All, I search on codeproject and google but didn't find what I was looking for. Anybody know of a good implementation where you have 2 listboxes and you want to move items between the 2. ...
1
by: Refugnic | last post by:
I tried to fill a ListBox with a DataSource pointing to an ArrayList. It all works fine...up to one point. The ArrayList is dynamic, which means the contents of it change, during the course of...
6
by: kimiraikkonen | last post by:
Hi, I can read from a text file and insert text file's contents into a listbox whose format is line by line using this code: Dim reader As String reader = My.Computer.FileSystem.ReadAllText("c:...
1
by: divya | last post by:
Hello, I used the below code to move selected items between two listboxes Left and Right:- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestPopup.aspx.cs" Inherits="TestPopup" %> ...
1
by: PaulBrains | last post by:
I was trying to sum up all the items of a listbox in Visual Studio 2005. I tried to loop (from 0 to ListBox.Items.Count - 1) as follows For j as Integer = 0 to ListBox.Items.Count - 1 ...
2
by: gnosys | last post by:
In ASP.Net 1.1 using C#, I'm trying to dynamically change the background colors of certain listbox items based on some criteria. For example:
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.