Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why does .Visible say False when it's True?

Status
Not open for further replies.

jsteph

Technical User
Oct 24, 2002
2,562
0
0
US
Hi
I have a form (vb6) that is Loaded in a module function. In the debug window, after the .Show, I do ?frmMain.Visible,
and the answer is "False". Same with every control on the form. Yet, of course, I can see them all and enter data, etc. There is *no* code that explicitly sets *any* properties of any control or the form. Why is this?
--jsteph
 
John,
Thanks for replying. I found the issue--it was my reference to the form. I had used the forms name in the debug window, but in the code there was a Form Object variable that was set as New, so the .Loaded form was the new instance of the form object.

What I don't understand is why referring to frmMain (the form's name) in the debug window didn't give an Object Varialbe Not Set error. The variable was Set F = New frmMain, and I am able to check F.Visible correctly, but refering to frmMain.Visible should give an error, right, since it's not Loaded or Set?
--jsteph
 
Because in VB6 there is an invisible
Dim formname as New formname
created for every form, e.g.
Dim frmMain as New frmMain

Remember, New "object" does not take effect until the first reference. Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
The act of referring to any of a form's built-in properties or methods causes that form to be loaded implicitly.
 
...and not just the built-in ones, either - referring to any of a form's properties or methods, built-in or otherwise, will implicitly load the form.
gkrogers
 
Thanks all, that clears it up alot. That 'invisible dim' stuff is tricky, but I can see the purpose for it.
--jsteph
 
Au contraire, Mr Rogers. Which is why I made that specific statement.

Create a project with two forms. On the second form, drop in this code:
[tt]
Option Explicit

Public frmvarTest As Long

Public Property Get frmProptest() As Long
frmProptest = frmvarTest
End Property

Public Property Let frmProptest(NewValue As Long)
frmvarTest = NewValue
End Property

Private Sub Form_Load()
Debug.Print "Loading Form2..."
End Sub
[/tt]
Now, on the first form create a command button, and then drop in the following code:
[tt]
Option Explicit

Private Sub Command1_Click()
Form2.frmProptest = 5
ListLoadedForms "Custom Property Let"

Debug.Print Form2.frmProptest
ListLoadedForms "Custom Property Get"

Debug.Print Form2.frmvarTest
ListLoadedForms "Custom Public Variable"

' Only on this one does Form2 actually get implicitly loaded
Debug.Print Form2.Width
ListLoadedForms "Built-in Property Get"
End Sub


Private Sub ListLoadedForms(strCause As String)
Dim strMsg As String
Dim myForm As Form
strMsg = "After " & strCause & ": currently loaded form(s) is/are: "
For Each myForm In Forms
strMsg = strMsg & myForm.Name & " "
Next
MsgBox strMsg
End Sub
 
You are indeed correct Mr Strong - I should have known better than to think that I could catch you making a sloppily worded post... :)

I did create a test project to check my assertion before I posted it, but I obviously managed to build a bug into it(which is quite remarkable, given the vanishingly small size of it), and then didn't bother saving it because it was so trivial... D'oh! gkrogers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top