Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default 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
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
How to send HP printer escape codes from Excel? MRBILLK Excel Programming 3 July 6th 06 02:09 PM
How to give escape sequence in Excel string literals... [email protected] Excel Programming 2 August 9th 05 07:38 AM
Need to Escape from Excel Forumla Hell! Julie P. Excel Worksheet Functions 3 April 29th 05 05:07 PM
How to count process running time ( process not finished) miao jie Excel Programming 0 January 13th 05 09:23 AM
How to count process running time ( process not finished) miao jie Excel Programming 2 January 12th 05 06:01 AM


All times are GMT +1. The time now is 02:38 AM.

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"