HELP? Trying to display form using event(button_Click) VB.net

I am trying to display form2 by using a button_click event on form 1. This used to be so easy in VB 6.0 : formname.show. Why microsoft decided to make it so difficult I will never know. I have researched it at MSDN web site, Microsoft Knowledge base, ect but nothing seems to work. Here is what I have tried:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim form2 as new form ()
form2.show () 'Also tried form2.showdialog
end sub
This approach makes a new blank form display when I click on a button1 (Form1). Not the intended form.

so I tried this:
Dim form2 as form ()
form2.show ()
end sub
This gives me an error message : An unhandled exception of type 'System.NullReferenceException' occurred in application.exe

Additional information: Object reference not set to an instance of an object.

Someone please help me. I am debating scrapping the project in .net and using 6.0.



Comments

  • : I am trying to display form2 by using a button_click event on form 1. This used to be so easy in VB 6.0 : formname.show. Why microsoft decided to make it so difficult I will never know. I have researched it at MSDN web site, Microsoft Knowledge base, ect but nothing seems to work. Here is what I have tried:
    :
    : Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    : Dim form2 as new form ()
    : form2.show () 'Also tried form2.showdialog
    : end sub
    : This approach makes a new blank form display when I click on a button1 (Form1). Not the intended form.
    :
    : so I tried this:
    : Dim form2 as form ()
    : form2.show ()
    : end sub
    : This gives me an error message : An unhandled exception of type 'System.NullReferenceException' occurred in application.exe
    :
    : Additional information: Object reference not set to an instance of an object.
    :
    : Someone please help me. I am debating scrapping the project in .net and using 6.0.
    :
    :
    :
    :

    Try this instead ...

    Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click

    Dim someForm as new form2()
    form2.show ()

    end sub

    The name of the form class is the actual name of the object you are instantiating. The generic Form class is the actual base class.

    Hope this helps.




  • I think that will work, but how do I define form2? VB tells me form2 is not defined. I'm new to vb.net.

    :
    :
    :

  • Dim formName as new form2()
    FormName.show()

    Try that.
    -Fallen

  • : Dim formName as new form2()
    : FormName.show()
    :
    : Try that.
    : -Fallen
    :
    : Thanks for your reply. This VB.net is drving me nuts, I am used to VB 6.0. I have already tried :

    Dim formname as new form2() 'VB tells me that form2 is not defined.
    Formname.show()

    What am I doing wrong. Surely it can't be this difficult...

  • : : Dim formName as new form2()
    : : FormName.show()
    : :
    : : Try that.
    : : -Fallen
    : :
    : : Thanks for your reply. This VB.net is drving me nuts, I am used to VB 6.0. I have already tried :
    :
    : Dim formname as new form2() 'VB tells me that form2 is not defined.
    : Formname.show()
    :
    : What am I doing wrong. Surely it can't be this difficult...
    :
    :
    well form2 would actually be the name of your 2nd form. So replace form2 with what ever it`s name is.

    -Fallen


  • Thanks alot!! I don't know why it was so hard for me. You saved me alot of headaches!!!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories