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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Call a function in another programm

Status
Not open for further replies.

imox

Programmer
May 13, 2013
37
DE
Hello,

with DO can I call a procedure or function in another program, but when I call a function do not get back anything. It is possible to do it?

Thanks

Imox
 
It's not possible for a function to return nothing.

If the function has a RETURN <expression> statement, it will return whatever the value of the expression is. If it doesn't have that statement, it will return .T.

If you are not seeing any returned value, is it possible that the returned value is in fact an empty string?

All of the above also applies to procedures.

By the way, this has got nothing to do with the fact that the function is in another program. The fact that you don't get an error when you call the function indicates that that is not a problem.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
How exactly are you calling those functions?

If you are calling them via DO SOMEFUNCTION IN SOMEPROGRAM, how are you capturing the return values?

Some code showing exactly what you are doing would be nice.

mmerlinn


Poor people do not hire employees. If you soak the rich, who are you going to work for?

"We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding. Answering questions for careless and sloppy thinkers is not rewarding." - Eric Raymond
 
Good point. Mmerlinn.

Imox, if you call a function with DO, there's no way to pick up the returned value. You have to call it as a function.

In other words, instead of this:

Code:
DO MyFunction

you must do this:

Code:
luReply = MyFunction()

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
if you call a function with DO, there's no way to pick up the returned value.
In general this is true,
But there is a way to get a 'returned' value from a DO is to use SCOPE.

Before calling the DO Routine, define a variable.
Then DO Routine where the variable exists due to SCOPE and where its value is modified. (make certain that the variable is not declared as PRIVATE in the DO Routine)
Upon returning from the DO Routine, the variable will have the modified value.

Example:
Code:
cReturnThisValue = ''  && Define variable desired to be returned.
* --- Now call your routine ---
DO SOMEFUNCTION IN SOMEPROGRAM  && Execute routine where cReturnThisValue is modified
* --- Now, Upon Return to the calling program the modified value of cReturnThisValue is usable ---

Its not elegant and it smacks of 'old school' methodology, but it works.

Now having explained that, I agree that it would be far better to use a FUNCTION() and call it as such - where this round-about approach is not necessary.

Good Luck,
JRB-Bldr
 
In my view, the best solution to the original problem is to limit each PRG to a single routine. Procedure files are a PITA and should be avoided.

Tamar
 
Are you really talking about a PRG file, when you say "another program"?

If you want to call another EXE, then you can either use RUN /N or the usual routines to start new processes via Windows API CreateProcess and the like. If you google that in conjunction with VFP you'd find the declaration needed to make use of the API function(s). There are many different approaches with or without waiting for the end of the new process, starting with certain user credentials etc.

Bye, Olaf.
 
SET PROCEDURE TO PROGRAMM

and then I can use the functions. This is what I'm looking for. But thanks for all. I don't want run a exe or something else. I want run a function from another program in foxpro.

 
SET PROCEDURE TO PROGRAMM

and then I can use the functions.

True. But that wasn't your original problem. You were saying that you "do not get back anything from the function". That's got nothing to do with SET PROCEDURE.

mIKE

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Ok maybe I explained it bad, but this was my problem ;)
 
I'll repeat that the best answer is to break up that procedure file, putting each procedure/function into a separate PRG with the same name as the procedure or function.

That said, if you SET PROCEDURE, you can call the routines inside as functions.

Tamar
 
MikeLewis said:
True. But that wasn't your original problem. You were saying that you "do not get back anything from the function". That's got nothing to do with SET PROCEDURE.

Perhaps it does. Perhaps he found "DO <program> IN <filename>, which would suffer from "not get back anything" where SET PROC would allow calling it as a function and solve the problem.

English is tough enough for me as a first language. [smile]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top