Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 252
Default how to know a caller at run-time

Hi all,

Is it possible to tell a caller in its callee sub? This question originates
from the following senario:

in the change event handler of a sheet, application.screenupdaing is set
true at the end of sub. there is a caller sub will cause the handler run
many times and do not hope the application.screenupdating restore to true in
the middle.

Clara
--
thank you so much for your help
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default how to know a caller at run-time

I think what you're asking is, can you determine from where a sub is
being called? In other words, who is the parent of this child that is
executing.

First I should point out, I'm no expert, so somebody else probably has
a better way. However, two ways I can think of a

1) If you're calling routines yourself, simply pass in that info. as
an argument to the called routine.

So for example if parent calls childA, then you'd have:
Sub Parent()

call childA ("Parent's Name")

end Sub

Then childA will know who called it.


2) If you're talking about a routine that executes based on an
interupt or callback, you could declare a global variable, and each
time you enter a new routine, you change the global to indicate the
name of the routine.

Something like...

Sub DoSomething_Click()

msgbox "I was called by", MyName ' prints last value of "MyName"

MyName="DoSomething_Click" ' update "MyName"

code....

end Sub

Stick that in every function you have. Not a perfect solution, but
better than nothing. Again, maybe someone else has a better idea, I'm
new to programming Excel and VBA.

Personally I just walk through the code, tracing one step at a time.


On Jun 4, 12:05*pm, clara wrote:
Hi all,

Is it possible to tell a caller in its callee sub? This question originates
from the following senario:

in the change event handler of a sheet, application.screenupdaing is set
true at the end of sub. *there is a caller sub will cause the handler run
many times and do not hope the application.screenupdating restore to true in
the middle.

Clara
--
thank you so much for your help


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 252
Default how to know a caller at run-time

Hi Dudely,

Thank you very much! I like your secod idea since I can avoid a lots change
in code.

Clara
--
thank you so much for your help


"Dudely" wrote:

I think what you're asking is, can you determine from where a sub is
being called? In other words, who is the parent of this child that is
executing.

First I should point out, I'm no expert, so somebody else probably has
a better way. However, two ways I can think of a

1) If you're calling routines yourself, simply pass in that info. as
an argument to the called routine.

So for example if parent calls childA, then you'd have:
Sub Parent()

call childA ("Parent's Name")

end Sub

Then childA will know who called it.


2) If you're talking about a routine that executes based on an
interupt or callback, you could declare a global variable, and each
time you enter a new routine, you change the global to indicate the
name of the routine.

Something like...

Sub DoSomething_Click()

msgbox "I was called by", MyName ' prints last value of "MyName"

MyName="DoSomething_Click" ' update "MyName"

code....

end Sub

Stick that in every function you have. Not a perfect solution, but
better than nothing. Again, maybe someone else has a better idea, I'm
new to programming Excel and VBA.

Personally I just walk through the code, tracing one step at a time.


On Jun 4, 12:05 pm, clara wrote:
Hi all,

Is it possible to tell a caller in its callee sub? This question originates
from the following senario:

in the change event handler of a sheet, application.screenupdaing is set
true at the end of sub. there is a caller sub will cause the handler run
many times and do not hope the application.screenupdating restore to true in
the middle.

Clara
--
thank you so much for your help



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
application.caller Alexander Excel Programming 3 December 8th 06 11:18 PM
application caller Rich Excel Programming 1 September 21st 06 07:48 PM
Row = Application.Caller.Row Charles Woll Excel Worksheet Functions 8 February 28th 05 02:04 PM
Application.Caller Mark Worthington Excel Programming 9 February 12th 04 07:32 PM
application.caller Jase Excel Programming 0 January 6th 04 03:51 AM


All times are GMT +1. The time now is 02:37 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"