ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Make VBA wait for return from external function (https://www.excelbanter.com/excel-programming/421888-make-vba-wait-return-external-function.html)

Gib Bogle

Make VBA wait for return from external function
 
When a function in a DLL (maybe created with C or Fortran) is called
from VBA, execution of the VBA code continues without waiting for the
called function to return. Is there a way to make VBA wait?

Leith Ross[_715_]

Make VBA wait for return from external function
 

Gib Bogle;165101 Wrote:
When a function in a DLL (maybe created with C or Fortran) is called
from VBA, execution of the VBA code continues without waiting for the
called function to return. Is there a way to make VBA wait?


Hello Gib,

Your statement "function to return" is ambiguous. To mean return a
value back to VBA, return to VBA when the function has finished running,
or both?

Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.thecodecage.com/forumz/member.php?userid=75
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=45830


Peter T

Make VBA wait for return from external function
 
Search this group for "Shell and Wait". There are various approaches, which
will depend on what you are doing overall.

Regards,
Peter T

"Gib Bogle" wrote in message
...
When a function in a DLL (maybe created with C or Fortran) is called from
VBA, execution of the VBA code continues without waiting for the called
function to return. Is there a way to make VBA wait?




Gib Bogle

Make VBA wait for return from external function
 
Peter T wrote:
Search this group for "Shell and Wait". There are various approaches, which
will depend on what you are doing overall.

Regards,
Peter T


I did that, and found only your post.
I would have thought that "Shell" applied to executing an external
process rather than to a call to a DLL routine. Am I wrong?

Peter T

Make VBA wait for return from external function
 
"Gib Bogle" wrote in message
Peter T wrote:
Search this group for "Shell and Wait". There are various approaches,
which will depend on what you are doing overall.


I did that, and found only your post.


So it does, sorry about that, try "ShellAndWait"

I would have thought that "Shell" applied to executing an external process
rather than to a call to a DLL routine. Am I wrong?


Yes you are right and perhaps I misunderstood your situation. Reading your
OP again I don't understand why there is such a problem calling your dll.
Normally when VBA (or an Excel formula) calls a function, even an external
function in a dll, code waits until the function returns its result.

Regards,
Peter T



Peter T

Make VBA wait for return from external function
 
PS
Are you sure there is nothing in the the dll function that leads to
asynchronous behaviour

Regards,
Peter T



Gib Bogle

Make VBA wait for return from external function
 
Peter T wrote:
PS
Are you sure there is nothing in the the dll function that leads to
asynchronous behaviour

Regards,
Peter T



To be honest this is not my problem. A poster asked this question on a
Fortran forum, and my curiosity was provoked. The poster says that
"...Excel 2007 VBA skips over calls [to his Fortran DLL] that take any
time to execute. If I go into debug mode for the VBA and pause after
the call the code completes and the results are passed into Excel."
This doesn't eliminate the possibility that there is something wrong
with the way he handles the returned results when not in debug mode.

Gib

Harald Staff[_2_]

Make VBA wait for return from external function
 

"Gib Bogle" wrote in message
...
To be honest this is not my problem. A poster asked this question on a
Fortran forum, and my curiosity was provoked. The poster says that
"...Excel 2007 VBA skips over calls [to his Fortran DLL] that take any
time to execute. If I go into debug mode for the VBA and pause after the
call the code completes and the results are passed into Excel."


If it works stepping and pausing through, a simple
DoEvents
usually does the trick when you want to wait for a calculation or similar.
(Not including full loading of webpages and such demanding tasks)

X = MyBogusFunction(y)
DoEvents
Range("A1").Value = X

HTH. Best wishes Harald


Gib Bogle

Make VBA wait for return from external function
 
Harald Staff wrote:

"Gib Bogle" wrote in message
...
To be honest this is not my problem. A poster asked this question on
a Fortran forum, and my curiosity was provoked. The poster says that
"...Excel 2007 VBA skips over calls [to his Fortran DLL] that take any
time to execute. If I go into debug mode for the VBA and pause after
the call the code completes and the results are passed into Excel."


If it works stepping and pausing through, a simple
DoEvents
usually does the trick when you want to wait for a calculation or
similar. (Not including full loading of webpages and such demanding tasks)

X = MyBogusFunction(y)
DoEvents
Range("A1").Value = X

HTH. Best wishes Harald


Thanks, I'll pass that advice on.


All times are GMT +1. The time now is 01:43 PM.

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