Hi Genetic,
|| fMAIN.Hide() - Hid the form the old fashioned way - it rebooted
|| my computer. Crude but effective
ROFL.
Strange though - hiding the startup Form shouldn't present any problems.
System.Windows.Forms.Form is a class. In any class, the variables that you
declare belong to that class. You can't get to those variables from outside
the class without referencing the class - either using the class name or an
instantiated object of that class.
In other words, if you declare
Public fONE As New System.Windows.Forms.Form
in the class form1 (non startup form) and call
fONE.Show
from your startup form, it <will indeed> say "Name fONE is not declared.
This is because the startup form doesn't have a variable called fONE - you
declared it in form1. You need a form1 to access the variable fONE.
There. I'm sure that's cleared that up!!
|| I also tried: Public f1 As New System.Windows.Forms.Form
|| in a module.
That's fine.
|| At this point, the module doesnt know what form I'm referring to.
Actually you're still mostly fine. The variable f1 has been given an
actual Form to show because you used the New keyword. You could say f1.Show
and it would work (and give you a blank form). But that declaration is only
'mostly' because you're after a form1 not a blank form.
|| since i'm not decalring inside a form.
Strictly speaking, you can declare a form variable anywhere that you can
define variables. Declaring form variables inside Form classes is not
obligatory.
|| So I added:
|| f1 = form1 'Compiler error.
|| And I got "declaration expected" for f1 (which I just declared) .
This is again correct. Read my last post again and see if it makes anymore
sense. I'll carry on anyway, though. "form1" is the name of the <class>. You
can't Show, Hide or do <anything> with a form1 - because it's the name of the
class. But you can make <instances> of form1. These will be actual Forms that
you <can> show and hide, etc.
f1 = form1 won't give you a form1 but you were close. You needed to add
the New keyword to make an instance.
f1 = New form1
========================================================
This issue is a major stumbling block for many programmers coming from VB6
to VB.NET.
Forms are no longer just there. They have to be managed. What's worse is
that I'm not quite telling the truth. The .NET designers, in an effort to be
helpful, have hidden some of the code that, if it had to be done manually,
would make things clearer.
In C#, if you want a form, you have to code its declaration and its
instantiation and then show it. All C# programs start with their "Sub Main".
This creates the startup form and off you go. Being explicit means less
confusion.
In VB, if you don't use Sub Main as your starting point, the compiler
effectively creates it for you - behind the scenes. And thus the confusion
starts! Here you have an obviously visible form which has appeared out of
nowhere. There is no variable with which to access it from outside the form.
There is little (to a newcomer from VB6) to say that this Form1 is <not> the
form that you can see, but is the class (template) for the form.
Create a project with a single form, Form1 and this is what you get
(simplified)
Class Form1
Sub Main
Dim f As New Form1
Application.Run (f)
End Sub
Sub New
Sub Form1_Load
End Class
But you never get to see the Sub Main as this is done for you and hidden.
In VB6, Form1 would be the class <and> the instance. In VB.NET, Form1 is the
class <only> while f, the hidden variable, is the instance.
Let's put Sub Main into a module:
Module LetsGo
Public f As New Form1
Sub Main
Application.Run (f)
End Sub
End Module
Class Form1
Sub New
Sub Form1_Load
End Class
Now you have a global variable, f, which is the actual form. You can
access this variable from anywhere and use it to Show and Hide, etc.
Ok, that's enough for now.
Have a read of this and read my last post again to get as much sense out
of them as possible. If possible get a beginning book on VB.NET so that you
can read what I've been saying in another way. The distinction that you're
after is that Forms and Form classes are now totally distinct where once they
were seemingly interchangeable.
Come back with any more questions. We'll get you there!
Regards,
Fergus