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!

Returning more than one value from a Form 1

Status
Not open for further replies.

arlequin

Programmer
Sep 21, 1999
232
UY
Hello, folks!

I am using
Code:
DO FORM
Code:
 myForm
Code:
WITH
Code:
 myVar
Code:
TO
Code:
 RetValue
in order to store a return value into
Code:
RetValue
which will be evaluated after. In form
Code:
myForm
the value is stored as a form property and it's updated a few times after being returned in the
Code:
RETURN
statement placed in the form's Unload event.

But I want to return more than one value from the form
Code:
myForm
, so I tried to set up and array as a form's property, but I found it's not allowed...

How can I manage to return more than one value from a form?

Perhaps I should return a comma separated value where each field would be each one of the values I want to return...

I am running MS-Visual FoxPro Version 7.

Thanks!

Arlequín
arlequin@montevideo.com.uy
 
Arlequin,

A form is just like a function in this respect -- it can only return single values.

One solution is to create an object to hold your return values. Store each value in a property of the object, and return the entire object to the caller.

Another possibility: When the user exits the form, don't close it immediately -- just make it invisible. At that point, control will return to the caller (yes, even though the form's modal). The caller can then extract the information it needs directly from the form's own properties. When it has done so, it can release the form.

Mike


Mike Lewis
Edinburgh, Scotland
 
You can indeed create a property of a form which is an array. Just add the property like:

myNewProperty[1]

I do it all the time.

Jim
 
jimstarr,
how do you access that array return by the form.
thanks
 
Arlequin,

Make your return value the type of String. When returning more than one value, you use a seperator like a semicolon in your returning string result.

So returning an integer (23) and a date type (24/06/2003), it wil look something like this "23;24/06/2003"

Then create a generic function to read the returning values.

Gr,
Andre
 
andre65,
That's what I had in mind. I think I'll be parsing the returning string.

jimstarr,
As remsor says... how can I store and access that array returned by the form?

Thanks for all.

Arlequín
arlequin@montevideo.com.uy
 
You can only get the result if you use Private/Public array.
Try this code:

in PRG:
-------
Private paTest
Dimension paTest[2]

? 'Before:'
For x = 1 To Alen(paTest)
? 'paTest[' + alltrim(str(x)) + '] = ', paTest[x]
Next

Do form test
Read events

?
? 'After:'
For x = 1 To Alen(paTest)
? 'paTest[' + alltrim(str(x)) + '] = ', paTest[x]
Next



in Form (Test.scx):
-------------------
- add aTest[1] properties

*** Form Load event
ACopy(paTest, ThisForm.aTest)

*** Form Unload event
With ThisForm
Dimension .aTest[10]
For x = 1 to 10
.aTest[x] = x
Next
Dimension paTest[ALen(.aTest)]
ACopy(.aTest, paTest)
EndWith
Clear events


-- AirCon --
 
Although it's easy to create an array as a form property it may not be all that helpful in your case, as Mike Lewis and AirCon point out.

If you have something like an application object whose properties are available throughout the application you can add the needed properties there. Then the called form places values in them, and the calling program can see them.

If you don't have such an object you can use the trick of adding the properties to the _SCREEN object via the ADDPROPERTY method.

Jim
 
Try using this code ...

*Myform
Myform.Getval
DO FORM FormRetVal NAME loGetretVal LINKED
Getretval1 = loGetretVal.value1
Getretval2 = loGetretVal.value2
RELEASE loGetretVal

*FormRetVal
OKbutton.click()
form.value1 = '12345'
form.value2 = 'ABCDE'
form.Hide

*Alwi*
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top