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

PASSING A VALUE FROM ONE FORM TO ANOTHER FORM 3

Status
Not open for further replies.

dakotafox

Programmer
Apr 14, 2000
53
0
0
US
I am working in VFP6.0 and fairly new to the visual foxpro world and am having great difficulty in knowing how to pass a value from one form to another consistently. So far I have occasionally accomplished it through trial and error. I would appreciate any tips you may have
 
Well, there are a couple of ways. One way is you could create a global variable - this is the easiest way, but it's an Object-Oriented no-no. A better way is to store custom properties on the form(s). The only thing there is that you have to know - or find out - that the other form is really there before you can use the value.<br><br>For example if you had 2 forms, Form1 and Form2, you could create a custom property on Form1 called customval. Then from Form2 you could see it by referencing Form1.customval (or from Form1 as ThisForm.customval). Hope this helps - SK
 
Let me add two more methods (no pun intended):<br><br>* Pass the parameter(s) to the second form, and include the <FONT FACE=monospace>PARAMETERS</font> statement in the second form's <FONT FACE=monospace>INIT</font> method.&nbsp;&nbsp;If you need the passed parameter beyond the second form's <FONT FACE=monospace>INIT</font>, then create a new property in the second form and store the passed parameter there, like this:<br><br>[TT]* -- FORM 2 INIT<br>LPARAMETER MYPARAM<br>THIS.PASSEDPARAM = MYPARAM</font><br><br>* A second, more complicated way is similar to SKelly's note about a global (public) variable.&nbsp;&nbsp;You could create a higher-level non-visual object, and put the necessary parameter(s) in it as properties of that object.&nbsp;&nbsp;A bit more work, but it'll impress your friends, and you'll eventually find that in the OOP world you can use that high-level object to store your &quot;globally-available&quot; properties, plus library-type methods you now may have scattered amongst PRGs. <p>Robert Bradley<br><a href=mailto: > </a><br><a href= - Visual FoxPro Development</a><br>
 
You can also return values from the 2nd form back to the first form with RETURN val1, val2, etc in its Unload event.&nbsp;&nbsp;The 2nd Form's WindowType must be set to (1) Modal if you do.<br><br>DO MyForm2 WITH var1, var2 TO retval1, retval2<br><br>This is one of the few examples the VFP Dev Guide is actually pretty clear and helpful on.<br><br>John Durbin<br>
 
If it's something that's going to be used thoughout the application, you might want to create a global object and reference it from there.<br><br>If you're passing the value to just one form, using the 'parameter' idea is good.&nbsp;&nbsp;You can also say something like thisform.myvar.value = form1.myvar.value ...but once you start doing this if the user has 2 form1's running at the same time VFP can screw ya.&nbsp;&nbsp;At this point you have to determine what's on top of the stack. <p>Victor Anderson<br><a href=mailto:victoranderson2000@imailbox.com>victoranderson2000@imailbox.com</a><br><a href= Guru</a><br>ICQ# - 14847018
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top