how to tracking function run time

M

miao jie

Hi, everyone
Do VBA support thread method ?? right now I wanna call a
time-consuming function to receive data from external system(SAP)
call ReceiveData()
this function will take some time to get data. sometimes, the external
system(SAP) will pop up a message box to tell some warning information. in
this case, the function is stop running and waiting user input "enter" key to
eliminate that message box to make my VBA program continus running.
I don't know how to capture SAP message box in VB, so my purposed
solution is count the function running time, if it takes more than 10
minutes(normally less than 10 minutes), I will use VB to simulate "enter" key
press with VBA.
My question is: how to start a thread to tracking the function
running? anybody can help me out, thanks in advance.

Public Declare Sub keybd_event Lib _
"user32" (ByVal bVk As Byte, ByVal Scan As Byte, _
ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Sub test()
Dim lngStart As Double
Dim lngStop As Double
Dim lngTime As Double

lngStart = Timer
' //// need start a tracking process here ------- help
call ReceiveData ' start data receive

'//// need check whether the function is running in each of 5 minutes
--- help

lngStop = Timer
ingTime = ingStop - ingStart
if ingTime < 10*60 then
Call keybd_event(13, 0, 0, 0) ' VB simulate "enter" key press
end if

End Sub
 
T

Tom Ogilvy

No. Excel VBA doesn't support multithreading within its code path. It can
start asynchronous processes with the Shell command.

Without seeing the receivedata routine, I would say your code will remain in
receivedata routine until it gets a return value from from the SAP
application - unless you are calling it asynchronously or it immediately
provides a return value when called.

If your receivedata is doing some DDE code, then DDE is asynchronous.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top