Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Excel COM dll - how to escape from process
Hi,
I have built a fairly simple Excel COM addin in visual basic 6 which loop 50000 times and adds up numbers. The problem I am having is that when I press the escpae key the COM addin doesn't stop (I would have expected it to - the same as VBA macros). Is there anything I need to do to put into my COM addin to allow this to happen? Many thanks for your help Mac |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Excel COM dll - how to escape from process
I recall struggling with that one!
This is what I eventually came up with for use in a VB6 dll - Private Declare Function GetAsyncKeyState Lib "user32" ( _ ByVal vKey As Long) As Integer Function IsKeyDown(key As Long) As Boolean If GetAsyncKeyState(key) Then IsKeyDown = True End If End Function Function EscBreak() As Long If IsKeyDown(vbKeyCancel) Then EscBreak = 8218 ' ctrl-break ElseIf IsKeyDown(vbKeyPause) Then EscBreak = 8218 ' simply Break ElseIf IsKeyDown(vbKeyEscape) Then EscBreak = 8219 ' Esc End If End Function Sub test() Dim i As Long Dim x As Double Dim nextKeyCheck As Long Dim nKey As Long Const cLOOPS As Long = 20000 ' adjust ' adjust cLOOPS to trigger every say 0.1 to 0.2 seconds ' EnableCancelKey in VBA only for testing ' don't include EnableCancelKey in VB6 Application.EnableCancelKey = xlDisabled On Error GoTo errH For i = 1 To 100000000 x = x + 0.01 If i nextKeyCheck Then nextKeyCheck = nextKeyCheck + cLOOPS nKey = EscBreak If nKey Then Err.Raise 12345 nKey = 0 End If End If Next i = i - 1 done: Debug.Print i, x ' note floating point error!! Application.EnableCancelKey = xlInterrupt Exit Sub errH: If Err.Number = 12345 Then If MsgBox("You pressed " & IIf(nKey = 8218, "Break", "Esc") & _ " in loop " & i & vbCr & _ "Do you want to continue", vbYesNo) = vbYes Then Resume Next Else ' do cleanup stuff Resume done End If Else ' some other error End If End Sub Regards, Peter T "mac_in_sctland" wrote in message ... Hi, I have built a fairly simple Excel COM addin in visual basic 6 which loop 50000 times and adds up numbers. The problem I am having is that when I press the escpae key the COM addin doesn't stop (I would have expected it to - the same as VBA macros). Is there anything I need to do to put into my COM addin to allow this to happen? Many thanks for your help Mac |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How to send HP printer escape codes from Excel? | Excel Programming | |||
How to give escape sequence in Excel string literals... | Excel Programming | |||
Need to Escape from Excel Forumla Hell! | Excel Worksheet Functions | |||
How to count process running time ( process not finished) | Excel Programming | |||
How to count process running time ( process not finished) | Excel Programming |