Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

For Loop with Skip 1

Status
Not open for further replies.

suoirotciv

Programmer
Dec 3, 2002
205
PH
I'm already doing this code below
Code:
Public Sub testloop()
   Dim x
   
   For x = 1 To 10
      Select Case loopr
         Case 1, 3, 7 To 10
            Debug.Print loopr
      End Select
   Next 
End Sub

But is there a way for the loop to look like this? Ofcouse the sample below is not working [upsidedown]
Code:
Public Sub testloop()
   Dim x As Integer
   
   For x = 1, 3, 7 To 10
       Debug.Print loopr
   Next 
End Sub

========================================
I kept my Job because of TEK-TIPS
Thanks a lot to all who keeps on helping others.
 
Unfortunately not I'm afraid. There are different ways to achieve what you want but they are basically variations on what you've currently got.

The only thing close in a FOR..LOOP construct is to use STEP but because of the values you're using that's not possible in this case.

Hope this helps

HarleyQuinn
---------------------------------
Carter, hand me my thinking grenades!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before posting.

 
Thanks! I was just thinking of a possible shorter method.

========================================
I kept my Job because of TEK-TIPS
Thanks a lot to all who keeps on helping others.
 
You can use Array function:
Code:
For Each x In Array(1, 3, 7, 10)
    Debug.Print x
Next x

combo
 
[2thumbsup]

Cool!!! that was great.

Thanks a lot.

========================================
I kept my Job because of TEK-TIPS
Thanks a lot to all who keeps on helping others.
 

in your code

Public Sub testloop()
Dim x As Integer

For x = 1, 3, 7 To 10
Debug.Print loopr
Next
End Sub

Public Sub testloop()
Dim x As Integer

For x = 1 to 10
SELECT CASE X
Case 1, 3, 7 To 10
Debug.Print X ' ( not loopr )
End SELECT
Next
End Sub


Loopr is either a Non Existant Variable ... or possibly a global which would never be altered by this loop

 
hehehe it was just a typo error . . i just copy paste my original code and altered it for easy reading.

========================================
I kept my Job because of TEK-TIPS
Thanks a lot to all who keeps on helping others.
 
To correspond correctly to the original code:
Code:
For Each x In Array(1, 3, 7, [red]8, 9, [/red]10)
    Debug.Print x
Next x
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top