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

How do I return new values of variables from a method?

Status
Not open for further replies.

rpp

Programmer
Feb 28, 2002
32
0
0
US
Hi experts,

I cannot seem to have the new values returned from a method I have created in my app.

For instance, I have a form that initializes these values like so...
STORE address TO gcAddress
STORE '' TO mstno, mdir, mstname, mapt

Then I call and run my method...
oApp.ParseAddressSingle(gcAddress, mstno, mdir, mstname, mapt)

but the new results of the mstno, mdir, mstname, mapt, still come back as empty, if though I can see in my watch list them change then change back to empty?

What am i missing?

Thanks in advance.

Rich
 
Rich -

VFP by default passes variables by reference, it makes a copy of the values and your function uses the copies but never updates the original values. You need to pass your variables by reference - add a @ before each of your variables like this:

oApp.ParseAddressSingle(@gcAddress, @mstno, @mdir, @mstname, @mapt)

VFP will then use the actual variables you've created and if you change their values in your procedure it will persist where those variables have scope.

Hope that helps.
 
You can pass the vars via reference as stated above. Actually I now tend to return an object that is created in the procedure. I create it either using "scatter name" or employing the EMPTY class like this:

local loAddress as Object

loAddress = ParseAddress(gcAddress)

? loAddress.Name
? loAddress.Street

....


PROCEDURE ParseAddress(tcAddress as string) as object
local loRetVal as object
loRetVal = Create("EMPTY") && requires VFP8

****
do the parsing
***

addProperty(loRetVal, "cAddress", tcAddress)
addProperty(loRetVal, "cName", lcName)
addProperty(loRetVal, "cStreet", lcStreet)

return loRetval
ENDPROC


This allows very handy work like using structs in .NET or other languages and the complete address can be passed from here to there.

HTH





 
JBalcerzak,

I am sure you meant to say VFP by default passes variables BY VALUE...

Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top