I want to question for all. I use Visual Studio 2008. Why everytime i show my form, i must declaration variable. Example

Dim form1 as new Form1
form1.show()

Why i can't use form1.show() direction. My friend can use form1.show direction without declaration variable in Visual Studio 2008. What's wrong with my Visual Studio 2008???? Thank's for you replies...

There's nothing wrong with your Visual Studio.

Somewhere, your friend is creating a variable just like you. Otherwise an exception would occur (I believe it's the NullReferenceException) because the form hasn't been initialized before calling the Show() method.

I have to note though, I haven't messed with .Net above 2.0 (Not for lack of trying, but 2.0 is all the company will allow) so maybe he's using a new version the .Net framework.

Thank's for your replies...

wheter i must install dot net framework new version just i can used method show???. I' m right....

i really dont know where the problem is o.O
just tested it with .NET 2.0
created two forms and added this code:

Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
        Form2.Show()
    End Sub

works like a charm.
I think you guys mixed the forms with Usercontrols. these have to be initialized before calling but forms not.

I think you guys mixed the forms with Usercontrols. these have to be initialized before calling but forms not.

Don't I have to create a variable to retrieve information or handle events from the form? (I'd test myself, but I'm currently fixing my VS 08 install)

I think there is an option in the IDE for automatically creating forms project wide. Your friend likely has his project setup differently.

if i look into the designer file of the forms it says:

Private components As System.ComponentModel.IContainer

    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        components = New System.ComponentModel.Container
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.Text = "Form2"
    End Sub

doesnt it mean that it creates a new instance on call?

This article has been dead for over six months. Start a new discussion instead.