Re: Using On Error to Exit Loop...ok?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Is this good and acceptable programming practice to
use "On Error GoTo.." as a way to exit a loop?

I don't like it.

On Error GoTo Found
Do While PictureBox1(free).Visible
free = free + 1
Loop

You can use this code to find the lowest unused Index value for your PictureBox1 control array without resorting to error trapping...

Dim S As String, C As Control, Free As Long
If PictureBox1.LBound = 0 Then
S = Space$(PictureBox1.UBound + 1)
For Each C In Controls
If TypeOf C Is PictureBox Then Mid(S, C.Index + 1, 1) = "X"
Next
Free = InStr(S, " ") - 1
End If
MsgBox "Lowest unused Index value = " & Free

--
Rick (MVP - Excel)



.



Relevant Pages

  • Re: COBOL aint quite dead - yet !
    ... of control there is nothing wrong with goto. ... The loop is entirely abstracted away. ... Then we have well-formed loops with a single invariant and a looping ...
    (comp.lang.cobol)
  • Re: GOTO and Bourne shell
    ... > You have a loop in some comms software. ... that would be another form of control coupling. ... An FSM has states, ... effect as if you used a goto. ...
    (comp.unix.shell)
  • Re: how do people feel about exit function from loop
    ... stand out to me far better than a For Next loop for that, ... line, the line that starts the loop, I know ALL the exit conditions for the ... And now we get back to why Goto is "silly" when Exit is not. ... as I have knowledge of only a few languages. ...
    (microsoft.public.vb.general.discussion)
  • Re: file copy routine
    ... using the jumps so I would not have to look up the iostat codes. ... to the bottom of the code separate from normal control flow. ... consider normal and indeed it is part of your your loop termination ... I will probably change to exit ...
    (comp.lang.fortran)
  • Re: Using Wildcards in a Select Case Statement ?
    ... you could, as above, use Exit Do. ... I have never *and I mean NEVER* needed a GoTo ... I have found a fair number of cases where a GoTo simplifies the code ...
    (microsoft.public.vb.general.discussion)