Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to return the name of a calling program?

Status
Not open for further replies.

mikemck7

Technical User
Dec 17, 2003
38
The PROGRAM() function returns the name of the currently running program. I need to be able to return the name of the program that called that program?. How is this done? I'm using VFP8
Thanks,
MikeM
 
You're close to the solution. Program(n) returns the name of the nth program in the stack. Start with n=1 and test Program(n) until it returns a blank string. That will tell you how deep the stack is and you can then call Program(n-1) to find the name of the previous program.

Geoff Franklin
 
Hi Mike and Geoff,

Take a look at the help and see that program(-1) tells you the actual stack level. Also look at SYS(16).

Bye, Olaf.
 
Yes, and SYS(16 tells you more and ASTACKINFO even tells you the line numbe from where the call came.

Bye, Olaf.
 
I tried this all out in FP 2.6 and came up with the following where N is the last item in stack (current program):

PROG(-1), PROG(0), & PROG(1) all return the name of the first program in stack
PROG(2) ... PROG(N) return the names of the 2nd thru Nth programs in the stack

SYS(16) returns current program name including extension (last program in stack), without the path
SYS(16,-1), SYS(16,0), & SYS(16,1) all return the full pathname of the running application
SYS(16,2) ... SYS(16,N) return the names of the 2nd thru Nth programs in the stack including extensions, but without the path
SYS(16)/SYS(16,X) NEVER returns the name of the first program in the stack


mmerlinn

"Political correctness is the BADGE of a COWARD!"

 
Thanks everyone. I went with Alvechurchdata's suggestion, Program(Program(-1)-1)), [minus the extra ")"] simply becase it seemed to be the simplest to implement. It worked for me.
Regards,
MikeM
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top