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 a value from a form

Status
Not open for further replies.

FoxEgg

Programmer
Mar 24, 2002
749
AU
I have a form FINDER which finds a person and then calls another with a parameter...

DO FORM INFORMATION WITH cPerson

Form INFORMATION runs and loads up whosoever is in cPerson. When I am done with that form and escape (hitting escape returns me) it returns to the original FINDER.. All is good.

Now if I want to call a ZIP_CODE_FINDER from INFORMATION, I use

DO FORM ZIP_CODE_FINDER from within FORM INFORATION

and THAT works fine too.... up pops ZIP_CODE_FINDER


AND NOW FOR THE QUESTION...

Once the ZIP is found, how do I return the ZIP code that I found to INFORMATION ?...

It seems that I should use the destroy event, but If I use

DO FORM INFORMATION WITH cZip

I think will be initiating another instance of the INFORMATION form...

Can I get some assistance as to the correct way as to how to return a number or should I just save it in a PUBLIC variable and use that ???

Thanks

FoxEgg

 
to have a form return a value use:

return myvalue

in "unload" of the form.
When you call the form use:

do form myform to lcValue

lcValue will now contain whatever was returned in the unload event of the form. Also, you must make the form windowstate modal.

Randy



 
FoxEgg,

As Randy has pointed out, you need to isse a RETURN in the called form's Unload (not the Destroy). However, be aware that, at the point at which Unload fires, all the controls on the form will already have been destroyed. So you cannot directly return the value of a control. You would need to store that value temporarily in a form property before you return it.

Note also that this whole thing will only work if the called form is modal.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-consult.com)
 
Thanks Randy, Thanks Mike

I discovered the Unload thingy when VFP got upset with me,,, I guessed that I had to use a temporary variable,,

Also VFP insisted that I used Modal (damned if I REALLY underestand modal modeless etc I just do it)


Here is part 2 of the question

How can I return 2 (or more) bits of information..

I have Suburb and Zip to come back...


I tried

return my_value, my_other_value

No way Jose... VFP continued to growl.. (An aside: It is like being married; you have to do everything correct, or you cop it from VFP)

Or do I have to use

do form myform to lcValue, lcValue2

?

I will try the latter....

Please accept this post as a major thankyou


John Fox






 
Or I suppose I could concatenate the variables and split them on return.

eg Surbiton;2111

and search for the ";" and split it off and separate.

JF
 
Dr. JF

If you want to avoid having to use a modal form.
BTW modal mean the form is the only accessible object in your application and modeless means othe objects and controls like menus and other forms are accessible - and the normal use of a modal form is to control the value or answer the user is going to give you.

Anyways, I would suggest you create a global custom class with the required propreties to store and use a regular form (not modal) and once the user has given you the values - store them in the global calls, destroy the form and the values are still available. Here is simplefied version. Once you input values in the textbox and release the form, use the debugger to note that the global class properties still contain the values.
Code:
PUBLIC oform1,oGlobal
oglobal = NEWOBJECT('oglobal')
oform1=NEWOBJECT("form1")
oform1.Show
RETURN
DEFINE CLASS form1 AS form
	DoCreate = .T.
	Caption = "Form1"
	Name = "Form1"
	ADD OBJECT text1 AS textbox WITH ;
		Height = 23, ;
		Left = 36, ;
		Top = 36, ;
		Width = 100, ;
		Name = "Text1"
	ADD OBJECT text2 AS textbox WITH ;
		Height = 23, ;
		Left = 204, ;
		Top = 36, ;
		Width = 100, ;
		Name = "Text2"
	ADD OBJECT command1 AS commandbutton WITH ;
		Top = 168, ;
		Left = 108, ;
		Height = 27, ;
		Width = 84, ;
		Caption = "Exit", ;
		Name = "Command1"
	PROCEDURE command1.Click
		IF NOT EMPTY(thisform.text1.value) AND NOT EMPTY(thisform.text2.value)
			STORE thisform.text1.value TO oglobal.prop1
			STORE thisform.text2.value TO oglobal.prop2
		ENDIF
		thisform.Release 
	ENDPROC
ENDDEFINE
DEFINE CLASS oGlobal as Custom 
  prop1 =''
  prop2 = ''
ENDDEFINE




Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Hi Mike and Thanks...

You never cease to amaze me....

#1 thanks for the modality update

#2 thanks for the code AMAZING

I think it goes into the code of my form correct ?


Thanks

JF
(PS havent seen you in Oz lately... How is the Cellar empty?)

 
JF

I think it goes into the code of my form correct ?

The custom class? No I would put in in your main program, and even instanciate it in the beginning of you application loading and do not destroy it (it will remain accessible during your session). I normally use the type of class form all kings of things like storing username and user level, so I can determine the level of access troughout the session, or in the case of the username, perhaps stamp the name in a field to record "how updated this record".

(PS havent seen you in Oz lately... How is the Cellar empty?)

OZ is a vacation I have planned for 2006. My cellar IS empty and worst, our own "wine suppliers" here in Quebec have been on strike for the last two months. Maybe I'll move up my vacation plans ;-)




Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Code:
IF NOT EMPTY(thisform.text1.value) AND NOT EMPTY(thisform.text2.value)
Checking for an empty value works in this case but the logic gets complicated when there are more parameters or when some of them are optional. I'd add a third parameter to make future work easier:
Code:
DEFINE CLASS oGlobal as Custom
  prop1 =''
  prop2 = ''
  lSelected = .F. 
ENDDEFINE
Set lSelected .T. when the user presses the OK button, set it .F. when they press the Cancel button.

Geoff Franklin
 
John

If you have VFP 8 and as an alternative to creating your class based on 'custom':-
Code:
[COLOR=blue]oMainObject = CreateObject([Empty])
ADDPROPERTY(oMainObject,[DefaultPrinter],SET([PRINTER],2))[/color]
To remove a property:-
Code:
[COLOR=blue]REMOVEPROPERTY(oMainObject,[DefaultPrinter])[/color]
How can I create a simple forms manager? faq184-4838

provides a further example using 'empty'.

FAQ184-2483 - answering getting answered.​
Chris [pc2]
PDFcommandertm.net
PDFcommandertm.co.uk


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top