[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Getting the calling function NAME at run time

Posted on 1998-06-04
10
Medium Priority
?
377 Views
Last Modified: 2010-05-03
Hi,

I have a situation like this: I have some function, and when it starts I want to know which function called it.

For example, I have these functions F1() and F2() that call F3(). When I start F3 from F1 I want to get a message box
that says "Function F1() called me".

How can I do that? And I don't mean solutions like keeping a global string and fill the name of the current function whenever it starts. I want it to happen automatically!

Is it possible?
0
Comment
Question by:yronnen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +4
10 Comments
 
LVL 6

Expert Comment

by:clifABB
ID: 1462517
No.
0
 
LVL 1

Expert Comment

by:sirigere
ID: 1462518
I think this might solve the problem
In the Global module declare
Global FunctionCalled as string
sub f1()
msgbox functioncalled
functioncalled="function F1"
f2
end sub
sub f2()
msgbox functioncalled
functioncalled="function F2"
f3
end sub
sub f3()
msgbox functioncalled
functioncalled="function f3"
f2
end sub
sub main
functioncalled=""
f1
end sub
0
 
LVL 5

Expert Comment

by:bin_huwairib
ID: 1462519
I don't think this is possible in VB,  yronnen.
Beside you are loosing nothing when you use a global variable.

8) Bin Huwairib

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 5

Author Comment

by:yronnen
ID: 1462520
What I mean is that I want it to be done automatically!
I don't want to go to each function and add a line with its name.
0
 
LVL 1

Expert Comment

by:sirigere
ID: 1462521
To yronnen
Can i see the part of code where you are facing this problem?
0
 
LVL 1

Expert Comment

by:raygibbins
ID: 1462522
The global variable woudn't work, because depending on where you are in the program, other functions could also be setting this variable at the same time.
You would have to pass the FunctionName as a string to ensure that the called function knows who called it.

Paste this into a form, and Click it

Function CalledFunction(ByVal CallerFunctionName As String)
    MsgBox CallerFunctionName & " Called Me"
End Function
Private Sub Form_Click()
    CalledFunction "Form_Click"
End Sub

0
 
LVL 5

Author Comment

by:yronnen
ID: 1462523
You don't understand what I mean. I DO NOT want to go to every function that calls F3() and call it using their names. I want to get their names automatically.
0
 
LVL 18

Expert Comment

by:deighton
ID: 1462524
yronnen

I understand what you mean, but I don't know of any way to do it - but why do you want to do this?  What is the actual predicament you are facing ?

raygibbins,

Is that right?  That would mean VB was running more than one bit of code at once - I didn't think it could suddenly fly off to another routine unless there was a DoEvents - I never thought of this I'm scared.


0
 
LVL 3

Expert Comment

by:rmichels
ID: 1462525
FailSafe from NuMega can help you manage this problem, but...it does automatically add lines to each function to track the calling sequence.  Not what you want, but it does automate the process.

Also, under VB5 you can compile with symbols. Not sure it you can easily get to these symbols at run time (I think PSAPI.DLL under WIN32 has support to get this debug information)...but normally you would not ship a program with symbolic debug on.
0
 
LVL 6

Accepted Solution

by:
clifABB earned 100 total points
ID: 1462526
Based on comments subsequent to my short comment.  You can rest assured that it cannot be done.  Even the best profilers will place code in each module so that it can keep track of which modules are called from where.

Therefore, I feel confident that I can submit this as an answer.

"It is not possible."
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question