Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 73
Default Recursive Loop -- How to Stop It?

My question involves an Excel input file where people are supposed to enter
certain data ONLY on Thursday thru Sunday.
(1) On Save, ThisWorkbook code checks the day of the week, and if it's
outside that window, opens UserForm1 with a reminder message. This works.
(2) When the form activates, its code kicks off macro Flash1, which is
intentionally recursive, switching the reminder text between black and red
once per second to get the user's attention. This works too.
(4) the form's <OK button sets a global boolean to True and hides the
form. The boolean, in turn, SHOULD affect the next loop of the Flash1,
causing it to terminate, but it doesn't -- it keeps on running in the
background. (I also tried unloading the form rather than just hiding it, but
no good either.)

Can anybody tell me what I'm doing wrong? I've done similar things with
Access's Timer Event, but Excel's Application.OnTime apparently isn't quite
equivalent. (Full code follows.)

<<<ThisWorkbook Code
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
QuitNow = False
If Weekday(Date) < 4 Then UserForm1.Show
End Sub

<<<UserForm1 Code
Private Sub UserForm_Activate()
UserForm1.Label1.ForeColor = vbBlack
NTime = Now + TimeValue("00:00:01")
Application.OnTime NTime, "Flash1" 'runs Flash1 the FIRST time, after
which it runs itself recursively
End Sub

Private Sub cmdOK_Click()
QuitNow = True €˜seems like this should stop the Flash1 recursive loop, but
it doesnt€¦
UserForm1.Hide
End Sub

<<<MACRO CODE

Dim NTime As Date, QuitNow As Boolean €˜Global variables€¦
Sub Flash1()
If QuitNow = True Then GoTo StopNow
NTime = Now + TimeValue("00:00:01")
If UserForm1.Label1.ForeColor = vbBlack Then
UserForm1.Label1.ForeColor = vbRed
Else
UserForm1.Label1.ForeColor = vbBlack
End If
Application.OnTime NTime, "Flash1"
StopNow:
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Recursive Loop -- How to Stop It?

"exit sub" an idea?

"LarryP" schreef in bericht
...
My question involves an Excel input file where people are supposed to
enter
certain data ONLY on Thursday thru Sunday.
(1) On Save, ThisWorkbook code checks the day of the week, and if it's
outside that window, opens UserForm1 with a reminder message. This works.
(2) When the form activates, its code kicks off macro Flash1, which is
intentionally recursive, switching the reminder text between black and red
once per second to get the user's attention. This works too.
(4) the form's <OK button sets a global boolean to True and hides the
form. The boolean, in turn, SHOULD affect the next loop of the Flash1,
causing it to terminate, but it doesn't -- it keeps on running in the
background. (I also tried unloading the form rather than just hiding it,
but
no good either.)

Can anybody tell me what I'm doing wrong? I've done similar things with
Access's Timer Event, but Excel's Application.OnTime apparently isn't
quite
equivalent. (Full code follows.)

<<<ThisWorkbook Code
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
QuitNow = False
If Weekday(Date) < 4 Then UserForm1.Show
End Sub

<<<UserForm1 Code
Private Sub UserForm_Activate()
UserForm1.Label1.ForeColor = vbBlack
NTime = Now + TimeValue("00:00:01")
Application.OnTime NTime, "Flash1" 'runs Flash1 the FIRST time, after
which it runs itself recursively
End Sub

Private Sub cmdOK_Click()
QuitNow = True 'seems like this should stop the Flash1 recursive loop,
but
it doesn't.
UserForm1.Hide
End Sub

<<<MACRO CODE

Dim NTime As Date, QuitNow As Boolean 'Global variables.
Sub Flash1()
If QuitNow = True Then GoTo StopNow
NTime = Now + TimeValue("00:00:01")
If UserForm1.Label1.ForeColor = vbBlack Then
UserForm1.Label1.ForeColor = vbRed
Else
UserForm1.Label1.ForeColor = vbBlack
End If
Application.OnTime NTime, "Flash1"
StopNow:
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 73
Default Recursive Loop -- How to Stop It?

Tried that too without success.

"Gert-Jan" wrote:

"exit sub" an idea?

"LarryP" schreef in bericht
...
My question involves an Excel input file where people are supposed to
enter
certain data ONLY on Thursday thru Sunday.
(1) On Save, ThisWorkbook code checks the day of the week, and if it's
outside that window, opens UserForm1 with a reminder message. This works.
(2) When the form activates, its code kicks off macro Flash1, which is
intentionally recursive, switching the reminder text between black and red
once per second to get the user's attention. This works too.
(4) the form's <OK button sets a global boolean to True and hides the
form. The boolean, in turn, SHOULD affect the next loop of the Flash1,
causing it to terminate, but it doesn't -- it keeps on running in the
background. (I also tried unloading the form rather than just hiding it,
but
no good either.)

Can anybody tell me what I'm doing wrong? I've done similar things with
Access's Timer Event, but Excel's Application.OnTime apparently isn't
quite
equivalent. (Full code follows.)

<<<ThisWorkbook Code
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
QuitNow = False
If Weekday(Date) < 4 Then UserForm1.Show
End Sub

<<<UserForm1 Code
Private Sub UserForm_Activate()
UserForm1.Label1.ForeColor = vbBlack
NTime = Now + TimeValue("00:00:01")
Application.OnTime NTime, "Flash1" 'runs Flash1 the FIRST time, after
which it runs itself recursively
End Sub

Private Sub cmdOK_Click()
QuitNow = True 'seems like this should stop the Flash1 recursive loop,
but
it doesn't.
UserForm1.Hide
End Sub

<<<MACRO CODE

Dim NTime As Date, QuitNow As Boolean 'Global variables.
Sub Flash1()
If QuitNow = True Then GoTo StopNow
NTime = Now + TimeValue("00:00:01")
If UserForm1.Label1.ForeColor = vbBlack Then
UserForm1.Label1.ForeColor = vbRed
Else
UserForm1.Label1.ForeColor = vbBlack
End If
Application.OnTime NTime, "Flash1"
StopNow:
End Sub




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Recursive Loop -- How to Stop It?

how about another ontime set to 00

--
Don Guillett
SalesAid Software

"LarryP" wrote in message
...
My question involves an Excel input file where people are supposed to
enter
certain data ONLY on Thursday thru Sunday.
(1) On Save, ThisWorkbook code checks the day of the week, and if it's
outside that window, opens UserForm1 with a reminder message. This works.
(2) When the form activates, its code kicks off macro Flash1, which is
intentionally recursive, switching the reminder text between black and red
once per second to get the user's attention. This works too.
(4) the form's <OK button sets a global boolean to True and hides the
form. The boolean, in turn, SHOULD affect the next loop of the Flash1,
causing it to terminate, but it doesn't -- it keeps on running in the
background. (I also tried unloading the form rather than just hiding it,
but
no good either.)

Can anybody tell me what I'm doing wrong? I've done similar things with
Access's Timer Event, but Excel's Application.OnTime apparently isn't
quite
equivalent. (Full code follows.)

<<<ThisWorkbook Code
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
QuitNow = False
If Weekday(Date) < 4 Then UserForm1.Show
End Sub

<<<UserForm1 Code
Private Sub UserForm_Activate()
UserForm1.Label1.ForeColor = vbBlack
NTime = Now + TimeValue("00:00:01")
Application.OnTime NTime, "Flash1" 'runs Flash1 the FIRST time, after
which it runs itself recursively
End Sub

Private Sub cmdOK_Click()
QuitNow = True 'seems like this should stop the Flash1 recursive loop,
but
it doesn't.
UserForm1.Hide
End Sub

<<<MACRO CODE

Dim NTime As Date, QuitNow As Boolean 'Global variables.
Sub Flash1()
If QuitNow = True Then GoTo StopNow
NTime = Now + TimeValue("00:00:01")
If UserForm1.Label1.ForeColor = vbBlack Then
UserForm1.Label1.ForeColor = vbRed
Else
UserForm1.Label1.ForeColor = vbBlack
End If
Application.OnTime NTime, "Flash1"
StopNow:
End Sub



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 371
Default Recursive Loop -- How to Stop It?

Hi LarryP
The only change i made was to declare both variables Public and it worked
fine for me - assuming the cmdbutton is on the form of course.

Geoff

"LarryP" wrote:

Tried that too without success.

"Gert-Jan" wrote:

"exit sub" an idea?

"LarryP" schreef in bericht
...
My question involves an Excel input file where people are supposed to
enter
certain data ONLY on Thursday thru Sunday.
(1) On Save, ThisWorkbook code checks the day of the week, and if it's
outside that window, opens UserForm1 with a reminder message. This works.
(2) When the form activates, its code kicks off macro Flash1, which is
intentionally recursive, switching the reminder text between black and red
once per second to get the user's attention. This works too.
(4) the form's <OK button sets a global boolean to True and hides the
form. The boolean, in turn, SHOULD affect the next loop of the Flash1,
causing it to terminate, but it doesn't -- it keeps on running in the
background. (I also tried unloading the form rather than just hiding it,
but
no good either.)

Can anybody tell me what I'm doing wrong? I've done similar things with
Access's Timer Event, but Excel's Application.OnTime apparently isn't
quite
equivalent. (Full code follows.)

<<<ThisWorkbook Code
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
QuitNow = False
If Weekday(Date) < 4 Then UserForm1.Show
End Sub

<<<UserForm1 Code
Private Sub UserForm_Activate()
UserForm1.Label1.ForeColor = vbBlack
NTime = Now + TimeValue("00:00:01")
Application.OnTime NTime, "Flash1" 'runs Flash1 the FIRST time, after
which it runs itself recursively
End Sub

Private Sub cmdOK_Click()
QuitNow = True 'seems like this should stop the Flash1 recursive loop,
but
it doesn't.
UserForm1.Hide
End Sub

<<<MACRO CODE

Dim NTime As Date, QuitNow As Boolean 'Global variables.
Sub Flash1()
If QuitNow = True Then GoTo StopNow
NTime = Now + TimeValue("00:00:01")
If UserForm1.Label1.ForeColor = vbBlack Then
UserForm1.Label1.ForeColor = vbRed
Else
UserForm1.Label1.ForeColor = vbBlack
End If
Application.OnTime NTime, "Flash1"
StopNow:
End Sub






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 73
Default Recursive Loop -- How to Stop It?

"Forest for the trees"! That did it. Thanks.

"Geoff" wrote:

Hi LarryP
The only change i made was to declare both variables Public and it worked
fine for me - assuming the cmdbutton is on the form of course.

Geoff

"LarryP" wrote:

Tried that too without success.

"Gert-Jan" wrote:

"exit sub" an idea?

"LarryP" schreef in bericht
...
My question involves an Excel input file where people are supposed to
enter
certain data ONLY on Thursday thru Sunday.
(1) On Save, ThisWorkbook code checks the day of the week, and if it's
outside that window, opens UserForm1 with a reminder message. This works.
(2) When the form activates, its code kicks off macro Flash1, which is
intentionally recursive, switching the reminder text between black and red
once per second to get the user's attention. This works too.
(4) the form's <OK button sets a global boolean to True and hides the
form. The boolean, in turn, SHOULD affect the next loop of the Flash1,
causing it to terminate, but it doesn't -- it keeps on running in the
background. (I also tried unloading the form rather than just hiding it,
but
no good either.)

Can anybody tell me what I'm doing wrong? I've done similar things with
Access's Timer Event, but Excel's Application.OnTime apparently isn't
quite
equivalent. (Full code follows.)

<<<ThisWorkbook Code
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
QuitNow = False
If Weekday(Date) < 4 Then UserForm1.Show
End Sub

<<<UserForm1 Code
Private Sub UserForm_Activate()
UserForm1.Label1.ForeColor = vbBlack
NTime = Now + TimeValue("00:00:01")
Application.OnTime NTime, "Flash1" 'runs Flash1 the FIRST time, after
which it runs itself recursively
End Sub

Private Sub cmdOK_Click()
QuitNow = True 'seems like this should stop the Flash1 recursive loop,
but
it doesn't.
UserForm1.Hide
End Sub

<<<MACRO CODE

Dim NTime As Date, QuitNow As Boolean 'Global variables.
Sub Flash1()
If QuitNow = True Then GoTo StopNow
NTime = Now + TimeValue("00:00:01")
If UserForm1.Label1.ForeColor = vbBlack Then
UserForm1.Label1.ForeColor = vbRed
Else
UserForm1.Label1.ForeColor = vbBlack
End If
Application.OnTime NTime, "Flash1"
StopNow:
End Sub




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 371
Default Recursive Loop -- How to Stop It?

Hi LarryP
Pleased to help <g
I find using Option Explicit in each module is very helpful for trapping
such errors.

Geoff

"LarryP" wrote:

"Forest for the trees"! That did it. Thanks.

"Geoff" wrote:

Hi LarryP
The only change i made was to declare both variables Public and it worked
fine for me - assuming the cmdbutton is on the form of course.

Geoff

"LarryP" wrote:

Tried that too without success.

"Gert-Jan" wrote:

"exit sub" an idea?

"LarryP" schreef in bericht
...
My question involves an Excel input file where people are supposed to
enter
certain data ONLY on Thursday thru Sunday.
(1) On Save, ThisWorkbook code checks the day of the week, and if it's
outside that window, opens UserForm1 with a reminder message. This works.
(2) When the form activates, its code kicks off macro Flash1, which is
intentionally recursive, switching the reminder text between black and red
once per second to get the user's attention. This works too.
(4) the form's <OK button sets a global boolean to True and hides the
form. The boolean, in turn, SHOULD affect the next loop of the Flash1,
causing it to terminate, but it doesn't -- it keeps on running in the
background. (I also tried unloading the form rather than just hiding it,
but
no good either.)

Can anybody tell me what I'm doing wrong? I've done similar things with
Access's Timer Event, but Excel's Application.OnTime apparently isn't
quite
equivalent. (Full code follows.)

<<<ThisWorkbook Code
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
QuitNow = False
If Weekday(Date) < 4 Then UserForm1.Show
End Sub

<<<UserForm1 Code
Private Sub UserForm_Activate()
UserForm1.Label1.ForeColor = vbBlack
NTime = Now + TimeValue("00:00:01")
Application.OnTime NTime, "Flash1" 'runs Flash1 the FIRST time, after
which it runs itself recursively
End Sub

Private Sub cmdOK_Click()
QuitNow = True 'seems like this should stop the Flash1 recursive loop,
but
it doesn't.
UserForm1.Hide
End Sub

<<<MACRO CODE

Dim NTime As Date, QuitNow As Boolean 'Global variables.
Sub Flash1()
If QuitNow = True Then GoTo StopNow
NTime = Now + TimeValue("00:00:01")
If UserForm1.Label1.ForeColor = vbBlack Then
UserForm1.Label1.ForeColor = vbRed
Else
UserForm1.Label1.ForeColor = vbBlack
End If
Application.OnTime NTime, "Flash1"
StopNow:
End Sub




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
close workbook without closing excel and stop recursive function chris Excel Discussion (Misc queries) 3 July 10th 06 08:23 PM
Hot key to stop a LOOP joopdog[_3_] Excel Programming 5 February 9th 06 06:51 PM
how to stop program in a big loop? miao jie Excel Programming 1 December 13th 04 12:32 PM
how to stop a loop L775 Excel Programming 6 November 29th 04 08:37 PM
HELP!!!! Can't stop a loop (NOT an infinite loop) TBA[_2_] Excel Programming 3 December 14th 03 03:33 PM


All times are GMT +1. The time now is 08:40 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"