borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Add XML Elemens to a ComboBox)Next Topic (what is the difference between file and stream ?) New Topic New Poll Post Reply
AndreaVB Forum : VB.Net : Form Show?
Poster Message
rtbuquia
Level: Professor

Registered: 29-05-2003
Posts: 90

icon Form Show?

Is it possible to store the name of the Form in a variable and access that variable to show the Form in VB6? VB.Net?

Example:
    frm = Form1
    frm.Show

____________________________
rtbuquia

24-06-2004 at 01:30 AM
View Profile Send Email to User Show All Posts | Quote Reply
fabulous
Level: VB Guru


Registered: 03-08-2002
Posts: 439
icon 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

24-06-2004 at 11:45 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
johnedw
Level: Sage

Registered: 15-08-2004
Posts: 50
icon Re: Form Show?

Hey, I would believe this example uses late binding,(This may be a bit unrelated though... maybe it will help)

I wrote this terribly non commented example ...

http://www.windowsforms.com/Forums/ShowPost.aspx?tabIndex=1&tabId=41&PostID=18095

____________________________
Today is a new day, in
a world OF CODE!

15-08-2004 at 01:45 AM
View Profile Send Email to User Show All Posts ICQ | Quote Reply
AndreaVB Forum : VB.Net : Form Show?
Previous Topic (Add XML Elemens to a ComboBox)Next Topic (what is the difference between file and stream ?) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder