Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
TitleDemonstrate the visible and invisible natures of forms
DescriptionThis 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.
Keywordsform, invisible, invisible, hidden
CategoriesControls
 
Forms are a bit wierd because they have a visible and an invisible part. Try this:

  1. Show Form2.
  2. Enter some text on Form2. Click Show Form2 Text. You should see your text.
  3. 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.
  4. 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
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated