Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hello,
Is it possible to make VBA code time out after a while if it still hasn't finished? I'm working on a simulation, and depending on the parameters, it can sometimes keep on processing without ever reaching an answer. I cannot know in advance what parameters give answers, and what parameters don't. What I would like is that if an answer hasn't been found in 10 seconds, it should write "Inconclusive" or something similar in the result cell. How can I do this, if it's possible? Thanks :-) Regards, Nils Magnus |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
One way...
Declare a Boolean variable. Set it to FALSE before you start the processing loop. Also, just before you start the loop, set up an OnTime event which will change the variable to TRUE. Test the variable within your processing loop; if it is TRUE, stop processing and return the "inconclusive" result. For Example: Public StopNow As Boolean Sub AAAAA() 'Set StopNow to FALSE StopNow = False 'Set StopNow to TRUE in 10 seconds. Application.OnTime Now() + TimeValue("0:00:10"), "Inconclusive" 'Start loop Do While ... 'not valid; example only If StopNow = True Then MsgBox "Inconclusive" Exit Sub End If 'Do processing 'Include a DoEvents DoEvents Loop End Sub Private Sub Inconclusive() StopNow = True End Sub Hope this helps, Hutch "Nils Magnus" wrote: Hello, Is it possible to make VBA code time out after a while if it still hasn't finished? I'm working on a simulation, and depending on the parameters, it can sometimes keep on processing without ever reaching an answer. I cannot know in advance what parameters give answers, and what parameters don't. What I would like is that if an answer hasn't been found in 10 seconds, it should write "Inconclusive" or something similar in the result cell. How can I do this, if it's possible? Thanks :-) Regards, Nils Magnus |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
split post code (zip code) out of cell that includes full address | Excel Discussion (Misc queries) | |||
Shorten code to apply to all sheets except a few, instead of individually naming them, and later adding to code. | Excel Programming | |||
Protect Sheet with code, but then code will not Paste error. How do i get around this. Please read for explainations.... | Excel Programming | |||
Excel code convert to Access code - Concat & eliminate duplicates | Excel Programming | |||
SQLOLEDB Timeouts; setting from Excel | Excel Programming |