• Welcome to Valhalla Legends Archive.
 

vb.net for each with step?

Started by Imperceptus, July 28, 2009, 01:49 PM

Previous topic - Next topic

Imperceptus

I would like to use step in my code like so
            For Each att As objValue In SearchSet Step 2

            Next

but vs2k8 only seems to want to let me do

            For Each att As objValue In SearchSet
            Next

Is what I want to not possible without possibly doing?

            For Counter as Integer = lbound(searchset) to ubound(searchset) step 2
            Next


Thanks in advance
Quote from: Hazard on August 07, 2003, 03:15 PM
Highlight your entire code. Press the delete key. Start over again using Cuphead's CSB tutorial and work your way from their rather than raping code from downloaded sources meant purely for learning purposes. If this does not fix the problem, uninstall Visual Basic and get a new hobby. I suggest Cricket.

MyndFyre

You can't do this with a For Each loop; For Each is an implicit call to IEnumerable.MoveNext(). 

What you could do is save state:

Dim n As Integer = 0
For Each att As objValue In SearchSet
    n = n + 1
    If n Mod 2 = 0 Then
        Continue
    End If
    ' Other logic
Next


Not terribly good-looking or straightforward, but it could work.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Imperceptus

alrighty, will look into that one. and your right its ugly lol.
Quote from: Hazard on August 07, 2003, 03:15 PM
Highlight your entire code. Press the delete key. Start over again using Cuphead's CSB tutorial and work your way from their rather than raping code from downloaded sources meant purely for learning purposes. If this does not fix the problem, uninstall Visual Basic and get a new hobby. I suggest Cricket.