All About Visual Basic 6 Programming

Linking Two Forms

Posted by Psycho Programer On Monday, December 6, 2010 3 comments

  1. Click File >> New Project. You might be asked to save changes to the current project if you’ve been experimenting. If so, click the No button. If you want to keep your work, click Yes. Select Standard EXE from the New Project Window.

Standard EXE

2. Select the Form and change its property Name to frmFirst  and Caption to First.

3. Double-Click the Command Button control in the toolbox to create a command button of default size in the center of the form. Drag the button near the bottom center of the form.

4. Select Command Button and change its Name property to cmdSecond and Caption to &Second Form.

Form First

5. Now Right-Click Project1 (Project1) from Project Window, select Add >> Form to add a New Form.

Add Form

6. Select Form and click Open.

Add

7. Select the Form and change its property Name to frmSecond  and Caption to Second.

8. Double-Click the Command Button control in the toolbox to create a command button of default size in the center of the form. Drag the button near the bottom center of the form.

9. Select Command Button and change its Name property to cmdFirst and Caption to &First Form

Second Form

10. Now double-click the cmdSecond  button from frmFirst. Double-clicking a control (or a form) opens the Code window at the default event from the control. The default event for a command button is the Click event. This means that any code entered in the procedure will be executed when the user clicks the cmdFirst button.

Add the following lines of code between Private Sub and End Sub :

   1:  frmSecond.Show
   2:  Unload Me

11. The line of code frmSecond.Show  tells the program to show frmSecond (Second Form we created earlier)  and Unload Me  tells the form to unload itself whenever the user clicks the cmdFirst button.

cmdSecond_Click

12. Double click frmSecond (frmSecond) from the Project Window. Double-click the cmdFirst button to open the code window.

Add the following lines of code between Private Sub and End Sub :

   1:  frmFirst.Show
   2:  Unload Me

13. The line of code frmFirst.Show  tells the program to show frmFirst (First Form we created) and Unload Me tells the form to unload itself whenever the user clicks the cmdSecond button.

cmdFirst_Click

14 Save the project by pressing Ctrl + S from the keyboard or by clicking File >> Save and Run the program by pressing F5 from the keyboard. You should see a form, similar to the one in figure below.

Runtime

15. Click button Second Form. This will show second form as shown in figure below and unload itself. Click button First Form to go back to First Form.

After Click

3 comments:

Soviet Man Ligal said...

lala daami......... keep it up/////

Anonymous said...

this post was reali useful 4 d beginners lyk us...

Anonymous said...

Thank You and that i have a super offer you: What Renovations Can You Claim On Tax whole house renovation

Post a Comment