Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Interrupt handling

Status
Not open for further replies.

neeeel

Programmer
Oct 2, 2010
2
GB
I am writing code for an excel sheet, which constantly polls another application for information. I am having problems being able to interrupt this. My excel version, as far as I know, is Excel 2007

I did a quick search and came up with this code
Code:
Public Sub Start() 
    On Error Goto UserInterrupt 
    Application.EnableCancelKey = xlErrorHandler 
    For i = 1 To 10000000 
        For t = 1 To 10000 
        Next t 
    Next i 
    Exit Sub 
UserInterrupt: 
    If Err = 18 Then 
        If MsgBox("Stop processing?", vbYesNo) = vbNo Then 
             'Keep running at the point procedure was interrupted
            Resume 
        Else 
             'Handle other errors that occur
             'MsgBox Error(Err )
        End If 
    End If 
End Sub

When I run this, I can interrupt it for a certain amount of time, but as soon as Excels menu bar changes to "Not Responding", Excel whites out, I cant interrupt at all and have to shut down the program and restart. Why does it only work for a certain amount of time, and how do I get round this problem?

I have the same problem when I run this code with my code which polls the application. I can interrupt it for the first few seconds, then I get "Not Responding" and when I click on the Excel sheet it whites out.

thanks for any help
 


Hi,

Long answer: Explain what other application and the polling process.

Short answer: Check out DoEvents

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Thanks for your answer. I was going to say that the other application doesnt matter, since it was happening with the simple For loop, but on turning my PC on today, and running the For loop, it doesnt hang and I can interrupt it at any time. So I guess its the other application that is causing problems( memory probs?), when it is run, and which affects other procedures which are run afterwards.

I am using a COM class which provides a number of events,objects and functions for allowing excel to talk to Betting Assistant, an application which uses the Betfair API to get info, place and manage bets to Betfair betting exchange.

I will have a look at doEvents and see if does what I need.

Any other advice or hints appreciated
thanks
neil
 
There is wrong logic in the error handler:
If Err = 18 [!]that's only user interrupt case[/!] Then
If MsgBox("Stop processing?", vbYesNo) = vbNo Then
'Keep running at the point procedure was interrupted
Resume [!]user selected vbNo, return to the code[/!]
Else [!]user selected vbYes[/!]
'Handle other errors that occur
'MsgBox Error(Err )
End If
End If [!]end of error handler, no other than Err=18 cases[/!]

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top