ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   how to tracking function run time (https://www.excelbanter.com/excel-programming/328102-how-tracking-function-run-time.html)

miao jie

how to tracking function run time
 
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


Tom Ogilvy

how to tracking function run time
 
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.

--
Regards,
Tom Ogilvy
"miao jie" wrote in message
...
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





All times are GMT +1. The time now is 12:02 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com