473,397 Members | 1,950 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,397 software developers and data experts.

For each

cj
When I running a loop: For Each File As System.io.FileInfo In FileInfo
Is there a way to tell which file number (index) I'm currently on?
Actually I'd like the ability to skip to a particular index--either
forward or back. It'd be nice to be able to set the index back or
forward with a command button perhaps and the loop just move to that
position and continue forward from there.

I'm specifically interested in doing this in the for each loop.
Feb 6 '06 #1
13 2001
"cj" <cj@nospam.nospam> schrieb:
When I running a loop: For Each File As System.io.FileInfo In FileInfo
Is there a way to tell which file number (index) I'm currently on?
Actually I'd like the ability to skip to a particular index--either
forward or back. It'd be nice to be able to set the index back or
forward with a command button perhaps and the loop just move to that
position and continue forward from there.

I'm specifically interested in doing this in the for each loop.


I am curious why you are not using a 'For...To' loop.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Feb 6 '06 #2
cj
Curiosity is a good thing. Right? I think so. Initially there was no
need for the functionality I'm requesting now and For Each is IMHO
specifically made for looping through collections/arrays so I used it.

So, why don't I change to "For To" etc now? Well, I will if I have to.
I am just curious if I could do this in For Each.

Hope someone knows.
Herfried K. Wagner [MVP] wrote:
"cj" <cj@nospam.nospam> schrieb:
When I running a loop: For Each File As System.io.FileInfo In
FileInfo Is there a way to tell which file number (index) I'm
currently on? Actually I'd like the ability to skip to a particular
index--either forward or back. It'd be nice to be able to set the
index back or forward with a command button perhaps and the loop just
move to that position and continue forward from there.

I'm specifically interested in doing this in the for each loop.


I am curious why you are not using a 'For...To' loop.

Feb 6 '06 #3
"cj" <cj@nospam.nospam> schrieb:
Curiosity is a good thing. Right? I think so. Initially there was no
need for the functionality I'm requesting now and For Each is IMHO
specifically made for looping through collections/arrays so I used it.


I would say it has been introduced to simplify looping through a collection
or array when index-based access is not important. Obviously the latter is
important in the case you described...

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Feb 6 '06 #4
Cj,

A for each loop will only work forwards. You will need to use a for
next loop.

Ken
-------------------
"cj" wrote:
When I running a loop: For Each File As System.io.FileInfo In FileInfo
Is there a way to tell which file number (index) I'm currently on?
Actually I'd like the ability to skip to a particular index--either
forward or back. It'd be nice to be able to set the index back or
forward with a command button perhaps and the loop just move to that
position and continue forward from there.

I'm specifically interested in doing this in the for each loop.

Feb 6 '06 #5
Hi cj,

Thanks for posting!

As Ken and Herfried mentioned, the "For Each" statement is not like the
"For" loop statement. Since "For Each" statement is only working forward,
there is no need to supply the functionalilty of the index. In this
scenario, I suggest you use the "For" loop statement instead of. I
appreciate your understanding.

Regards,

Yuan Ren [MSFT]
Microsoft Online Support

Feb 7 '06 #6
CMM
Um, "IndexOf" function perhaps? Arrays have this as do all the collections
AFAIK.

Though I would agree with what the others recommed as IndexOf would probably
slow down your loop and is sorta dumb to use if you can just change your
look to For x.. To.
"cj" <cj@nospam.nospam> wrote in message
news:Oz****************@TK2MSFTNGP12.phx.gbl...
Curiosity is a good thing. Right? I think so. Initially there was no
need for the functionality I'm requesting now and For Each is IMHO
specifically made for looping through collections/arrays so I used it.

So, why don't I change to "For To" etc now? Well, I will if I have to. I
am just curious if I could do this in For Each.

Hope someone knows.
Herfried K. Wagner [MVP] wrote:
"cj" <cj@nospam.nospam> schrieb:
When I running a loop: For Each File As System.io.FileInfo In FileInfo
Is there a way to tell which file number (index) I'm currently on?
Actually I'd like the ability to skip to a particular index--either
forward or back. It'd be nice to be able to set the index back or
forward with a command button perhaps and the loop just move to that
position and continue forward from there.

I'm specifically interested in doing this in the for each loop.


I am curious why you are not using a 'For...To' loop.

Feb 7 '06 #7
CMM
The Proper way to code this would be to use a a Do Loop and control the
increment manually.

Do Until whatever_condition

'do whatever work on
'fileInfo(i)

If whatever Then
i += 1
Else whatever2 then
i -= 3
...
End If
Loop
"Ken Tucker [MVP]" <Ke**********@discussions.microsoft.com> wrote in message
news:82**********************************@microsof t.com...
Cj,

A for each loop will only work forwards. You will need to use a
for
next loop.

Ken
-------------------
"cj" wrote:
When I running a loop: For Each File As System.io.FileInfo In FileInfo
Is there a way to tell which file number (index) I'm currently on?
Actually I'd like the ability to skip to a particular index--either
forward or back. It'd be nice to be able to set the index back or
forward with a command button perhaps and the loop just move to that
position and continue forward from there.

I'm specifically interested in doing this in the for each loop.

Feb 7 '06 #8
cj
When I running a loop: For Each File As System.io.FileInfo In FileInfo Is
there a way to tell which file number (index) I'm currently on?


Yes there is, however very inefficient to use, and because of the code bad
to maintain, so probably only used by bad developpers who want to obfuscate
there programs direct for everybody.

http://msdn2.microsoft.com/system.co...numerator.aspx

The For Next Index gives all the information direct.

I hope this helps,

Cor
Feb 7 '06 #9
> The Proper way to code this would be to use a a Do Loop and control the
increment manually.

Do Until whatever_condition

'do whatever work on
'fileInfo(i)

If whatever Then
i += 1
Else whatever2 then
i -= 3
...
End If
Loop

Brrrrrrrrrrrrrrrr, proper for who, an assembler programmer, who learned less
or nothing from possibilities from higher languages.

Cor
Feb 7 '06 #10
CMM
Did you even read the poster's question?
Feb 7 '06 #11
CMM,

Yes even in Cobol does this give bad code (high change on errors). However
Cobol is in fact not event driven and therefore has less the problem from
recursive behaviour.

(I have the idea that cj asks this from a Cobol background).

Cor
Feb 7 '06 #12
CMM,.

You deserve it that I explain this Cobol part a little bit more, know that
it is for me as well very long back in time.

In Cobol is the instruction "Perform", an instruction I never saw back in
any other language. It is extremely powerfull.

You can handle with it an endless amount of tables wich can be endless deep
inside tables as well. Those can be referenced by direct pointers however as
well by referenced pointers. It is no problem to set them conditional up and
down whenever you want.

However you can more with it, you can as well perform performs inside a
perform, although you can do the same with a for in a for, is it with a
"perform" shorter to write.

Maybe I have for cj direct answers his problem with this.

Cor
Feb 7 '06 #13
cj
I had a lot of posts to this question after I left work yesterday so
I'll make one blanket reply here. Thanks! To everyone. Seems there is
a way with ienumerator (thanks Cor). But that does sound too
complicated for me to get into. At least I was not overlooking
something obvious.

I couldn't find any way to get the current index while in the "For Each"
loop. I'd thought of Indexof too and it should return the index of the
item I'm on. (Although if you have several identical items in a
collection that'd throw a wrench into that. For me if I used the file
name which would be logical it should be fine as there wouldn't be
duplicate file names.) However indexof will not allow me to reposition
the for each loop to a new index.

I'd envisioned something like the windows media player's progress bar.
In my program jpgs are flipped by one by one and the progress bar shows
how far through the available jpgs it' gone. In WMP I can click on the
progress bar and have it instantly jump to that place in the
song/movie/whatever and it jumps--forward or back--to that point and
continues playing forward from there.

I understood from the beginning this could be done in a "For To" loop.
And, it's absolutely no problem to change the program to "For To" loop.
I just wanted to know if I was overlooking some functionality in "For
Each" loop.

So, I changed to "For To" and now am looking at determining what index
to reposition to based on a click on a progress bar--see the post I made
4 hours after this one. Gary has made an interesting suggestion I think
I'll play around with.


cj wrote:
When I running a loop: For Each File As System.io.FileInfo In FileInfo
Is there a way to tell which file number (index) I'm currently on?
Actually I'd like the ability to skip to a particular index--either
forward or back. It'd be nice to be able to set the index back or
forward with a command button perhaps and the loop just move to that
position and continue forward from there.

I'm specifically interested in doing this in the for each loop.

Feb 7 '06 #14

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

Similar topics

4
by: Jean-Christophe Michel | last post by:
Hi, I have a stylesheet with an accumulator like this <xsl:param name="new-x"> <xsl:for-each select="anode"> <mynode> <xsl:attribute name="attr"> <xsl:value select="anode/atag" />...
2
by: matatu | last post by:
Hi to everybody, It's possible to exit from a cycle for-each? I have this code: 1: <xsl:for-each select="field"> 2: <xsl:variable name="tagfield" select="@tag"/> 3: <xsl:variable...
3
by: deko | last post by:
Problem: why doesn't this With block work? is it possible to have a For Each loop within a With block? With objWord .Documents.Add Template:=strTemplate, NewTemplate:=False, DocumentType:=0...
8
by: Floris van Haaster | last post by:
Hi All! I have a question, i have a web application and I store some member information in a variable i declared in a module like: Public some_info_variable as string in module1.vb But...
13
by: tshad | last post by:
Is there a way to run a script or function on entry of each page without having to put a call in each page? Periodically, I find something I want to do each time a page is entered and I have to...
6
by: Michael D. Ober | last post by:
In VB 6, the loop iterator v in the following code must be a variant. dim v as variant dim c as new collection for each v in collection ... next v What is the general translation in VB 7.1...
6
by: Neal | last post by:
Hi All, I used an article on XSLT and XML and creating a TOC written on the MSDN CodeCorner. ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/dncodecorn/html/corner042699.htm However, it did'nt...
9
by: xmlhelp | last post by:
stuff.XSL: <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:param name="uid"/> <xsl:template match="/"> parameter...
17
by: The Frog | last post by:
Hello everyone, I am working on an application that can build database objects in MS Access from text files. I suppose you could call it a backup and restore type routine. Accessing the...
0
ADezii
by: ADezii | last post by:
If you want to visit each item in an Array, you have two alternatives: Use a For Each..Next loop, using a Variant to retrieve each value in turn. Use a For...Next loop, looping from the Lower...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.