fabulous Level: VB Guru

 Registered: 03-08-2002 Posts: 439
|
Re: Form Show?
I think this calls for more than a simple answer.
___________________________________________
What used to happen in VB.OLD (from VB4 to VB6) is that when you created a form and gave it a name, (Form1 in this case), VB would create a hidden global variable with the same name for you to access in your code.
The reason this was so, was because VB had to be code compatible with the previous which were not object oriented. In the days of old, you could just call the form from somewhere but from VB4 the Form itself was now a Class with a visual representation or user interface. That meant you could now create Properties inside the forms, and you could also raise custom events from there.
You could now use features like Implements in a form to specify that it implemented a particular interface. With this feature, you could pass a form to the outside of your application even though it was illegal to pass a Form between projects, by implementing the interface you could now pass the form where the Interface was expected. You will note that only classes can implement interfaces, modules cannot.
For people who had been coding in VB before this feature was available, Microsoft had to allow them to call the form without having to declare a variable of that type. So each time you created a form, VB would create a hidden variable declaration which if seen would be as follows:
| Public Form1 As New Form1 |
VB.NET on the other hand, was not an upgrade of VB6. It introduced a whole paradigm shift. The .NET framework is a large framework that is accessed by all .NET languages and so Microsoft could not provide VB specific things anymore since some people could opt to use COBOL, PERL, FORTRAN or more likely C#, Visual C++ and of course VB. This meant that many of the luxuries you enjoyed had to be sacrificed, some of them were kept and can be found in the Microsoft.VisualBasic namespace.
VB is now fully object oriented and like the rest of the OO languages many things don't apply, you can no longer display a form by calling its show method, you have to declare a variable of that type:
Dim frm As Form1
frm = New Form1
frm.Show() |
or
Dim frm As New Form1
frm.Show() |
In short, you need to have an instance of Form1 before you can actually use the variable. To do that you have to use code similar to what I have done in the last 2 code snippets.
I hope that was helpful. Post back if you need more information. Happy coding.
____________________________
My boss is a Jewish Carpenter (Jesus Christ)

Brain Bench Certified VB.NET Developer
|