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!

Do program.prg

Status
Not open for further replies.

FoxWing

Programmer
Dec 20, 2004
44
GB
Hi,

I'm trying to execute a DO statement as follows :
DO check_status WITH 'T'

However, my check_stauts.prg has a RETURN statement.

How can i able to 'read' the return result from my prg program ?


Many thanks
 
One of 4 ways:

1- Define a private variable which the called program
knows about.

2- Pass in the name of the private variable in
a character variable (better)


3- Redesign so you can call it as a function and pass a variable by reference

4- Same as 3, but just return the value

* 3-4 can also be easily accomplished by issuing a
* set procedure to (program name) additive and calling
* your program as a function


1-
private vReturn
vReturn = .f. && Have to define the var
DO check_status WITH 'T'

procedure check_status
lparam vArg1
* Processing...

vReturn = somevalue

2-
private vReturn
vReturn = .f. && Have to define the var
DO check_status WITH 'T', "vReturn"

procedure check_status
lparam vArg1, vReturnVal
* Processing...

&vReturnVal = somevalue

3-
local vReturn
=check_status('T',@vReturn)

procedure check_status
lparam vArg1, vReturnValue
* Processing...

vReturnValue = somevalue

4-
local vReturn
vReturn = check_status WITH 'T'

procedure check_status
lparam vArg1
* Processing...

return somevalue
 
Forgot about globals(public) variables which can be the worst choice of all, but sometimes the most expedient.

Darrell
 
thank you very much for the quick response.
 
Just a couple notes:

VFP doesn't care whether a routine is declared as a FUNCTION or a PROCEDURE ... they are identical. The difference is simply as documentation. Both always return a value (which is .T. unless otherwise specified).

And, Number 4 above:
local vReturn
vReturn = check_status WITH 'T'

procedure check_status
lparam vArg1
* Processing...

return somevalue


...Has a syntax error: you cannot use "WITH" if you are calling a subroutine and assigning its result to a variable... this would work instead:
Code:
local vReturn
vReturn = check_status('T')

procedure check_status
lparam vArg1
* Processing...
return somevalue

- Bill

Get the best answers to your questions -- See FAQ481-4875.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top