Retrieve values from another form in Visual FoxPro 9.0

One of the ways to retrieve values from another form in Visual Foxpro is to use a Form Set. A Form Set (from the name itself) is a set or collection of forms. To create a Form Set, follow these steps:

1. Click Start>All Programs>Visual FoxPro 9.0.
2. Close the Task Pane Manager Window.
3. To create a form, type CREA FORM in the command window, and then press enter.



Note: If the Command Window is not shown, Press CTRL + F2.
4. A new form will now come into view.



5. To create a form set, click Form>Create Form Set.




Although nothing appear to happen when you click the Create Form Set Submenu but essentially a new submenu will be enabled, the Add New Form submenu.

6. To add a form to your Form Set, Click Form>Add New Form.



A new form named form2 will now be added to your Form Set. If you add another form, that form will be named form3 and so on. Repeat the step no. 6 to add one more form to your form set. Our form set will now have 3 forms named form1, form2, and form3.




7. For the sake of example, let’s make an application that will allow us to enter our first name in the first form, last name in the second form, and display our first name and last name in the last form. We also want to display just the main form when our application is first executed and hide the unneeded forms.

8. If we click the Run icon or press control + E now. you’ll noticed that all forms are displayed at once.




8. Click all the close button of all the opened form to go back to the design view. To hide Form2 and Form3 when the application is first executed, double Click Form1, in the Init procedure, enter the following:
*hides the second form
Thisformset.Form2.Hide ()
*hides the third form
Thisformset.Form3.Hide ()


The code window will now look like this:




9. While still in the code window of Form1, Select the Unload event.

Enter the following code:

*Closes all the forms in the formset
 RELEASE Thisformset


The code window will now look like this:



10. Click the close button of the code window to save all codes that we have entered so far in form1.

11. Add a Label, a textbox and a button to form1, refer to the following screenshot for control property values:




12. What we aim to do here is if click the next button, form1 will be hidden and form2 will appear. To be able to do that, double click the Next button in form1 and enter the following codes:

*Hides form1
Thisformset.Form1.Hide()
*Show form2
Thisformset.Form2.Show()

The code window will now look like this:



Click the close button of the code window to save the codes that we have entered in Command1.

13. Add a Label, a textbox and two buttons to form2, refer to the following screenshot for control property values:



14. What we intend to do here is if we click the Prev Button, Form2 will be hidden and Form1 will be shown. If we click the Next Form3 will be shown and Form2 will be hidden.

15. Double click the Prev button then enter the following codes:
*Shows form1
Thisformset.form1.Show()
*Hides form2
Thisformset.form2.Hide()

Your code window will now look like this:




Click the close of the code window to save your codes

16. Double click the next button in form2 then enter the following codes:
*Hides form2
Thisformset.form2.Hide()
*Shows form3
Thisformset.form3.Show()

Your code window will now look like this:



Click the close of the code window to save your codes

17. Add four labels to form3. Refer to the following screenshot for control property values:



18. What we intend to do here is if Form3 is loaded, all the values from the previous will be displayed on their respective controls. Double-click form3. Select the Activate procedure then enter the following codes:
*retrieves the value of the textbox in form1 and
*display it in the our label in form3
Thisformset.Form3.Label2.Caption=Thisformset.Form1.text1.value
*retrieves the value of the textbox in form2 and
*display it in our label in form3
Thisformset.Form3.Label4.Caption=Thisformset.Form2.text1.value

Your code window will now look like this:



19. Click the close button of the code window to save your codes. Let’s take a look to all our forms once more time.



20. Click the run icon or press Ctrl + E to test your Form Set.

21. Try entering your first name on form1>Next. Your Last name on Form2>Next. Your first name and last name should now appear on form3.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.