Advanced Programming Question 
Author Message
 Advanced Programming Question

If I have a While loop inside a For loop and do a Exit For in the While loop
am I not cleaning up right?  I'm worried (knowing VB and Microsoft) that
pointers are not being popped off the stack correctly or something like
that.  Another external event sets x and y.  Example:

Private Sub SomeProcedure()
  tmrPoll.Interval = 5000
  For i=1 To 3
    tmrPoll.Enabled = True
    While tmrPoll.Enabled
      DoEvents
      If x=y Then Exit For  '<--Is this gonna cause a problem?
    Wend
    If x=y Then Exit For
  Next
End Sub

Private Sub tmrPoll_Timer()
  tmrPoll.Enabled = False
End Sub

Tim :)

Tim Berneman

President of Central Iowa Visual Basic User Group (CIVBUG)
Webmaster of Central Iowa Visual Basic User Group (www.civbug.org)



Wed, 06 Mar 2002 03:00:00 GMT  
 Advanced Programming Question
Looks pretty sanitary to me.

doco


Quote:
> If I have a While loop inside a For loop and do a Exit For in the While
loop
> am I not cleaning up right?  I'm worried (knowing VB and Microsoft) that
> pointers are not being popped off the stack correctly or something like
> that.  Another external event sets x and y.  Example:

> Private Sub SomeProcedure()
>   tmrPoll.Interval = 5000
>   For i=1 To 3
>     tmrPoll.Enabled = True
>     While tmrPoll.Enabled
>       DoEvents
>       If x=y Then Exit For  '<--Is this gonna cause a problem?
>     Wend
>     If x=y Then Exit For
>   Next
> End Sub

> Private Sub tmrPoll_Timer()
>   tmrPoll.Enabled = False
> End Sub

> Tim :)

> Tim Berneman

> President of Central Iowa Visual Basic User Group (CIVBUG)
> Webmaster of Central Iowa Visual Basic User Group (www.civbug.org)



Wed, 06 Mar 2002 03:00:00 GMT  
 Advanced Programming Question


Quote:
> If I have a While loop inside a For loop and do a Exit For in
> the While loop am I not cleaning up right?  I'm worried (knowing VB
> and Microsoft) that pointers are not being popped off the stack
> correctly or something like that.

No. This is not recursion. No pointers are involved.

Quote:
> Tim Berneman

> President of Central Iowa Visual Basic User Group (CIVBUG)
> Webmaster of Central Iowa Visual Basic User Group (www.civbug.org)

-Amos Yung

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.



Thu, 07 Mar 2002 03:00:00 GMT  
 Advanced Programming Question
Use a Do loop so you can exit it instead:

Private Sub SomeProcedure()
  tmrPoll.Interval = 5000
  For i=1 To 3
    tmrPoll.Enabled = True
    Do While tmrPoll.Enabled
      DoEvents
      If x=y Then Exit Do
    Loop
    If x=y Then Exit For
  Next
End Sub


Quote:
> If I have a While loop inside a For loop and do a Exit For in the While
loop
> am I not cleaning up right?  I'm worried (knowing VB and Microsoft) that
> pointers are not being popped off the stack correctly or something like
> that.  Another external event sets x and y.  Example:

> Private Sub SomeProcedure()
>   tmrPoll.Interval = 5000
>   For i=1 To 3
>     tmrPoll.Enabled = True
>     While tmrPoll.Enabled
>       DoEvents
>       If x=y Then Exit For  '<--Is this gonna cause a problem?
>     Wend
>     If x=y Then Exit For
>   Next
> End Sub

> Private Sub tmrPoll_Timer()
>   tmrPoll.Enabled = False
> End Sub

> Tim :)

> Tim Berneman

> President of Central Iowa Visual Basic User Group (CIVBUG)
> Webmaster of Central Iowa Visual Basic User Group (www.civbug.org)



Thu, 07 Mar 2002 03:00:00 GMT  
 Advanced Programming Question
Looks fine to me. I use Exit Do and Exit For all the time..or at least where
needed.

David

Quote:

>If I have a While loop inside a For loop and do a Exit For in the While
loop
>am I not cleaning up right?  I'm worried (knowing VB and Microsoft) that
>pointers are not being popped off the stack correctly or something like
>that.  Another external event sets x and y.  Example:

>Private Sub SomeProcedure()
>  tmrPoll.Interval = 5000
>  For i=1 To 3
>    tmrPoll.Enabled = True
>    While tmrPoll.Enabled
>      DoEvents
>      If x=y Then Exit For  '<--Is this gonna cause a problem?
>    Wend
>    If x=y Then Exit For
>  Next
>End Sub

>Private Sub tmrPoll_Timer()
>  tmrPoll.Enabled = False
>End Sub

>Tim :)

>Tim Berneman

>President of Central Iowa Visual Basic User Group (CIVBUG)
>Webmaster of Central Iowa Visual Basic User Group (www.civbug.org)



Fri, 08 Mar 2002 03:00:00 GMT  
 Advanced Programming Question
Its fine. Try the following, which will run forever:

Private Sub Command1_Click()
Dim a, i
Do
For i = 1 To 3
  While a = a
    DoEvents
    Exit For
  Wend
Next i
Loop
Print "done"
End Sub

Mike


Quote:
> Looks fine to me. I use Exit Do and Exit For all the time..or at least
where
> needed.

> David




Quote:
> >If I have a While loop inside a For loop and do a Exit For in the While
> loop
> >am I not cleaning up right?  I'm worried (knowing VB and Microsoft) that
> >pointers are not being popped off the stack correctly or something like
> >that.  Another external event sets x and y.  Example:

> >Private Sub SomeProcedure()
> >  tmrPoll.Interval = 5000
> >  For i=1 To 3
> >    tmrPoll.Enabled = True
> >    While tmrPoll.Enabled
> >      DoEvents
> >      If x=y Then Exit For  '<--Is this gonna cause a problem?
> >    Wend
> >    If x=y Then Exit For
> >  Next
> >End Sub

> >Private Sub tmrPoll_Timer()
> >  tmrPoll.Enabled = False
> >End Sub

> >Tim :)

> >Tim Berneman

> >President of Central Iowa Visual Basic User Group (CIVBUG)
> >Webmaster of Central Iowa Visual Basic User Group (www.civbug.org)



Sat, 09 Mar 2002 03:00:00 GMT  
 Advanced Programming Question

Quote:

>If I have a While loop inside a For loop and do a Exit For in the While loop
>am I not cleaning up right?  I'm worried (knowing VB and Microsoft) that
>pointers are not being popped off the stack correctly or something like
>that.

No. It's safe. It used to be, for example in the BASIC on Apple II, that
the FOR counter was on the return stack. I'm not sure about VB, but
Exit For serves exactly to cleanly leave a FOR loop at any time.

But WHILE is nothing but a conditional goto, as is the WEND
(unconditional). Same for DO and LOOP. There's nothing on any stack for
these kinds of loop.

--
        Bart.



Sat, 09 Mar 2002 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Advanced programming question. Can this be done.

2. Advanced Programming -- Reading Data from an Active Program

3. Advanced Programming

4. intermediate - advanced game programming

 

 
Powered by phpBB® Forum Software