Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

#1
March 7th, 2012, 07:04 PM
 Ranakhu
Contributing User

Join Date: Jan 2009
Posts: 65
Time spent in forums: 13 h 36 m 42 sec
Reputation Power: 14
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
March 7th, 2012, 10:44 PM
 Doug G
Grumpier Old Moderator

Join Date: Jun 2003
Posts: 14,237
Time spent in forums: 1 Month 4 Weeks 14 h 47 m 12 sec
Reputation Power: 4445
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
======
It is a truism of American politics that no man who can win an election deserves to. --Trevanian, from the novel Shibumi

#3
March 7th, 2012, 11:31 PM
 Ranakhu
Contributing User

Join Date: Jan 2009
Posts: 65
Time spent in forums: 13 h 36 m 42 sec
Reputation Power: 14
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,

#4
March 8th, 2012, 11:08 AM
 medialint
Type Cast Exception

Join Date: Apr 2004
Location: OAKLAND CA | Adam's Point (Fairyland)
Posts: 14,938
Time spent in forums: 6 Months 2 Weeks 2 Days 19 m 8 sec
Reputation Power: 8490
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

 Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > For loop question