PC Review


Reply
Thread Tools Rate Thread

Detecting an endless loop in the VB Editor

 
 
Raj
Guest
Posts: n/a
 
      7th Jun 2008
Hi,

In events programming, not using Application.enableevents = True and
False code comibination may result in an endless loop.

Is there any way to detect whether an endless loop has been
trigerred? Is there any indication in the VB editor to indicate that
there is currently no endless loop running?

I am asking this as it may take quite some time before the system runs
out of resources because of the endless loop.

Thanks in advance for the help.

Regards,
Raj
 
Reply With Quote
 
 
 
 
CurlyDave
Guest
Posts: n/a
 
      7th Jun 2008
On Jun 7, 3:01 am, Raj <rsp...@gmail.com> wrote:
> Hi,
>
> In events programming, not using Application.enableevents = True and
> False code comibination may result in an endless loop.
>
> Is there any way to detect whether an endless loop has been
> trigerred? Is there any indication in the VB editor to indicate that
> there is currently no endless loop running?
>
> I am asking this as it may take quite some time before the system runs
> out of resources because of the endless loop.
>
> Thanks in advance for the help.
>
> Regards,
> Raj

Hi,
Click Ctrl-Break to stop the loop,
lets see the code....
 
Reply With Quote
 
Bob Bridges
Guest
Posts: n/a
 
      7th Jun 2008
I don't know of a practical way to make a program smart enough to know when
it shouldn't be doing what you told it to. You can, I think, have it check
the time at the beginning of a loop and then if it spends more than <n>
seconds inside the loop it can stop and display an abend message. But would
you want to do that with every loop you create in an event routine?

There is another way around it: A human can at some point get suspicious
and hit <Ctrl-Break> (or is it <Ctrl-SysRq>? I always get them confused),
which will cause the routine to stop and allow you to look at the debugger to
figure out what's going on; at that point you can decide whether to stop the
run, allow it to continue or fix the logic and let it go on from there.
That's helpful only when the user is also the author, of course, or at least
a VBA writer himself; if you're handing this routine to be used by others it
doesn't solve your problem.

--- "Raj" wrote:
> In events programming, not using Application.enableevents = True and
> False code comibination may result in an endless loop.
>
> Is there any way to detect whether an endless loop has been
> trigerred? Is there any indication in the VB editor to indicate that
> there is currently no endless loop running?
>
> I am asking this as it may take quite some time before the system runs
> out of resources because of the endless loop.

 
Reply With Quote
 
MatthewJJNorman@gmail.com
Guest
Posts: n/a
 
      24th Jun 2008
On Jun 7, 6:25*pm, Bob Bridges <BobBrid...@discussions.microsoft.com>
wrote:
> I don't know of a practical way to make a program smart enough to know when
> it shouldn't be doing what you told it to. *You can, I think, have it check
> the time at the beginning of a loop and then if it spends more than <n>
> seconds inside the loop it can stop and display an abend message. *But would
> you want to do that with every loop you create in an event routine?
>
> There is another way around it: *A human can at some point get suspicious
> and hit <Ctrl-Break> (or is it <Ctrl-SysRq>? *I always get them confused),
> which will cause the routine to stop and allow you to look at the debugger to
> figure out what's going on; at that point you can decide whether to stop the
> run, allow it to continue or fix the logic and let it go on from there. *
> That's helpful only when the user is also the author, of course, or at least
> a VBA writer himself; if you're handing this routine to be used by othersit
> doesn't solve your problem.
>
>
>
> --- "Raj" wrote:
> > Ineventsprogramming, not using Application.enableevents = True and
> > False code comibination *may result in an endless loop.

>
> > Is there any way to detect whether an endless loop has been
> > trigerred? *Is there any indication in the VB editor to indicate that
> > there is currently no endless loop running?

>
> > I am asking this as it may take quite some time before thesystemruns
> > out of resources because of the endless loop.- Hide quoted text -

>
> - Show quoted text -


Before I knew about Application.EnableEvents=TRUE, I stored a value in
a sheet if the code should not be run, and then checked this value in
the Event - if the value is true (ie "do not run event") I fired an
Exit Sub. I tried this with a Public variable - but it was a bit more
flaky...
 
Reply With Quote
 
Chip Pearson
Guest
Posts: n/a
 
      24th Jun 2008

> I tried this with a Public variable - but it was a bit more flaky...


Public variables can appear to behave oddly if you are editing code after
the value of a public variable has been set. This is because VBA will
determine that it needs to recompile a module or an entire project after
editing, and compilation dumps public variables out of memory, which means
they get reset to default values (0, False, vbNullString, or Nothing
depending on the data type).


--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)







<(E-Mail Removed)> wrote in message
news:778c28a1-1406-460b-ae2a-(E-Mail Removed)...
On Jun 7, 6:25 pm, Bob Bridges <BobBrid...@discussions.microsoft.com>
wrote:
> I don't know of a practical way to make a program smart enough to know
> when
> it shouldn't be doing what you told it to. You can, I think, have it check
> the time at the beginning of a loop and then if it spends more than <n>
> seconds inside the loop it can stop and display an abend message. But
> would
> you want to do that with every loop you create in an event routine?
>
> There is another way around it: A human can at some point get suspicious
> and hit <Ctrl-Break> (or is it <Ctrl-SysRq>? I always get them confused),
> which will cause the routine to stop and allow you to look at the debugger
> to
> figure out what's going on; at that point you can decide whether to stop
> the
> run, allow it to continue or fix the logic and let it go on from there.
> That's helpful only when the user is also the author, of course, or at
> least
> a VBA writer himself; if you're handing this routine to be used by others
> it
> doesn't solve your problem.
>
>
>
> --- "Raj" wrote:
> > Ineventsprogramming, not using Application.enableevents = True and
> > False code comibination may result in an endless loop.

>
> > Is there any way to detect whether an endless loop has been
> > trigerred? Is there any indication in the VB editor to indicate that
> > there is currently no endless loop running?

>
> > I am asking this as it may take quite some time before thesystemruns
> > out of resources because of the endless loop.- Hide quoted text -

>
> - Show quoted text -


Before I knew about Application.EnableEvents=TRUE, I stored a value in
a sheet if the code should not be run, and then checked this value in
the Event - if the value is true (ie "do not run event") I fired an
Exit Sub. I tried this with a Public variable - but it was a bit more
flaky...

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Endless Loop - Why? -Karl Microsoft Access Forms 2 17th Jul 2009 02:57 AM
Endless loop JesseRay Windows Vista General Discussion 9 8th Jul 2008 05:16 PM
Endless loop freddie mac Microsoft Excel Programming 2 1st Aug 2006 03:19 PM
RE: Endless loop? =?Utf-8?B?RlN0MQ==?= Microsoft Excel Programming 7 2nd Aug 2005 06:41 PM
Endless loop Looping Windows XP Setup 1 29th Oct 2003 01:01 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:43 AM.