#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2009
    Posts
    65
    Rep Power
    15

    For loop question


    Below is my For loop but I "Unexpected Next" error.

    Code:
    	For iPinRow = iPinNameRow+2 To usedRowsCount+1
    	
    		If iPinRow.Value = "" Then
    			Next
    		Else
                            ' do something
                    End If
     
            Next
    What am I doing wrong - any ideas?
  2. #2
  3. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,441
    Rep Power
    4539
    Get rid of the embedded next statement in the if. Just comment it out and your loop should work the way you want.
    ======
    Doug G
    ======
    Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.
    --Alfred Bester
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2009
    Posts
    65
    Rep Power
    15
    Thanks Doug,

    Actually, I wanted to know how to go the next iteration in the For loop (I am more used to Perl than VB so tried Next for the next iteration) - since there's no such thing as Next in VB, I used an IF statement for not equal and problem solved.

    Regards,
  6. #4
  7. Type Cast Exception
    Devshed Supreme Being (6500+ posts)

    Join Date
    Apr 2004
    Location
    OAKLAND CA | Adam's Point (Fairyland)
    Posts
    14,954
    Rep Power
    8617
    There is a Next of course you just can't put it in the middle of an If logic block.

    There is an Exit For if you wanted to break out of the loop altogether.

    example..

    Code:
    Sub TestFor()
        Dim n As Integer
        For n = 0 To 100
            If n Mod 13 = 12 Then
                Exit For
            End If
        Next
    End Sub
    VB also still has a GOTO but I've never encountered a use for it (except error handling) where the same thing couldn't be done with if/then or other logic.
    medialint.com

    “Today you are You, that is truer than true. There is no one alive who is Youer than You.” - Dr. Seuss

IMN logo majestic logo threadwatch logo seochat tools logo