Microsoft KB Archive/154666

= How To Create a Private Data Collection for an MDI Child Form =

Article ID: 154666

Article Last Modified on 7/13/2004

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 16-bit Enterprise Edition
 * Microsoft Visual Basic 4.0 32-Bit Enterprise Edition

-



This article was previously published under Q154666



SUMMARY
A form can contain public and private properties similar to the properties found in the Properties window of a form or component. You can associate data with individual forms by creating a property procedure. Property procedures allow individual forms to hold unique data sets.

This article demonstrates how to create property procedures with an MDI application containing a child form template. As a result of using this technique, each instance of the child form can then contain a unique data set.



Steps to Create Sample Program
 Start Visual Basic. Form1 is created by default. Add an MDI form to the project by completing the following steps:

 From the Project Menu, choose Add MDI Form. In Visual Basic 4.0, choose MDI Form from the Insert menu. Add a PictureBox control to the MDIForm1 form. Add a Command button to the PictureBox control.  Copy the following code to the Code window of the MDIForm1 form: Private Sub MDIForm_Load Command1.Caption = "New Child Form" End Sub

Private Sub Command1_Click Dim F As New Form1 F.Caption = "Child " & Forms.Count F.Show End Sub  Make the MDIForm1 form the startup form by completing the following steps:

<ol> From the Project menu, choose Project1 Properties. In Visual Basic 4.0, choose Options from the Tools menu, and select the Project tab.</li> Select MDIForm1 from the Startup Object dropdown. In Visual Basic 4.0, select MDIForm1 from the Startup Form dropdown. In the Startup Form combo box, click MDIForm1.</li> Click OK to close the dialog box.</li></ol> </li></ol> </li> Add another form to the project by completing the following steps:

<ol style="list-style-type: lower-alpha;"> Choose Add Form from the Project Menu. In Visual Basic 4.0, choose Form from the Insert menu.</li> Add two command buttons and two text box controls to the Form2 form.</li>  Copy the following code to the Code window of the Form2 form: Private Sub Form_Load Text1.Text = "" Text2.Text = "" Command1.Caption = "Set Property" Command2.Caption = "Get Property" End Sub

Private Sub Command1_Click With MDIForm1.ActiveForm .FirstName = Text1.Text .LastName = Text2.Text End With End Sub

Private Sub Command2_Click With MDIForm1.ActiveForm Text1.Text = .FirstName Text2.Text = .LastName End With End Sub </li> Make the following changes to the Form1 form.

<ol style="list-style-type: lower-alpha;"> Change the MDIChild property to True.</li> Add a command button.</li>  Copy the following code to the Code window of the Form1 form: Private TempFirstName As String Private TempLastName As String

Private Sub Form_Load Command1.Caption = "Show Dialog Box" End Sub

Private Sub Command1_Click Form2.Show End Sub

Public Property Get FirstName FirstName = TempFirstName End Property

Public Property Let FirstName(vNewValue) TempFirstName = vNewValue End Property

Public Property Get LastName LastName = TempLastName End Property

Public Property Let LastName(vNewValue) TempLastName = vNewValue End Property </li></ol> </li> Save the project.</li> Run the sample program by completing the following steps:

<ol style="list-style-type: lower-alpha;"> On the Run menu, click Start or press the F5 key to start the program.</li> Create two child forms by clicking the New Child Form button twice.</li> <li>For each child form, click the Show Dialog button to display a Form2 form.</li> <li>For each Form2 form, enter a different first and last name in the text boxes and click the Set Property button.</li> <li>From each child form, click the Show Dialog button again to display the Form2 form created from the child form. Click the Get Property button. Each Form2 form should contain its own first and last name data items in the text boxes.</li></ol> </li></ol> </li></ol>

Additional query words: kbVBp400 kbVBp500 kbVBp600 kbVBp kbdsd kbDSupport kbNoKeyWord

Keywords: kbhowto KB154666

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.