Title | Demonstrate the visible and invisible natures of forms |
Description | This example demonstrates the visible and invisible natures of forms in Visual Basic 6. It shows how variables declared on a form may persist even after a form is closed. |
Keywords | form, invisible, invisible, hidden |
Categories | Controls |
|
|
Forms are a bit wierd because they have a visible and an invisible part. Try this:
- Show Form2.
- Enter some text on Form2. Click Show Form2 Text. You should see your text.
- Click Close Form2. Click Show Form2 Text. You will still see your text. The visible component is gone but the invisible component that includes variables is still alive.
- Click Set Form2 = Nothing. Click Show Form2 Text. You will see a blank value. The invisible component is gone so you are now looking at a new default invisible component's value which is initially blank.
The following code is in Form2. It simply saves the text you type into the variable FormValue.
|
|
Public FormValue As String
Private Sub Text1_Change()
FormValue = Text1.Text
End Sub
|
|
The following code is in Form1. It lets you manipulate Form2.
|
|
Private Sub Command1_Click()
Form2.Show
End Sub
Private Sub Command2_Click()
MsgBox Form2.FormValue
End Sub
Private Sub Command3_Click()
Unload Form2
End Sub
Private Sub Command4_Click()
Set Form2 = Nothing
End Sub
|
|
|
|