Results 1 to 14 of 14

Thread: How to activate a form?

Hybrid View

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2003
    Posts
    11

    How to activate a form?

    I know in VB 6.0 the code to activate a form was...

    Private Sub cmdOK_Click ()

    frmMainForm.Show

    End Sub

    How can I do the same in VB.Net?

    Thanks

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    Dim frm As new Form1 ' <-Name of the form to load
    frm.Show
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    In .NET, in order to display a form, you first must create an instance of the class.

    Code:
        Dim frm As frmMain   ' Allocate memory on the heap for for object    
        frm = New frmMain()  ' Call class constructor to create and place object in heap

  4. #4
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    [LGS] beat me to the punch..

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2003
    Posts
    11
    I tried the above code but it gave me an error. Something like, Value of .... can not be converted into a one dimensional array. Can any body break it down some more for me?

  6. #6
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    post the code you used (Cut / paste)
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  7. #7

    Thread Starter
    New Member
    Join Date
    Feb 2003
    Posts
    11
    Here is the code I'm useing:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    'Click on button to open up Form2
    Dim MainFrom As New Form2()

    MainForm.show()





    End Sub

  8. #8
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Dim MainForm As Form2
    MainForm = New Form2()
    MainForm.Show()

  9. #9
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    is Form2 called form2??


    Dim frm As New Form1
    frm.Show()


    I dont get the () after the dim frm etc...hmmm

    odd that it wouldnt work for you...


    Hellswraith...if you do it like the code above.. you eliminate a whole step
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  10. #10
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    He did that in two lines because if you use NEW in the declaration line then it has to check to see if it has been created everytime it access the object. At least that is the way it was in VB6, I'm not sure if .NET is smarter or not. I hope it is considering everything is an object. By setting it on the next line it removes that check thus speeding up access to the object.

  11. #11
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Edneeis,
    Both ways of creating an object are equivalent in .NET. No longer is the additional overhead required when accessing an object this way.

  12. #12
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Good because I stopped doing it in .NET and always found it a bit annoying.

  13. #13

    Thread Starter
    New Member
    Join Date
    Feb 2003
    Posts
    11
    I tried to do this code in the form of Form 1 to load the Form2

    Dim MainForm as Form2

    (Then in the sub procedure)
    Private Sub cmdOK_Click()
    'Open up Form2

    MainForm = New Form2
    MainForm.Show

    End Sub

    This is exactly how I have it, and for some reason it gives me an error saying that "MainForm" is undeclared. Any body got any ideas?

  14. #14
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Why do you have the declaration of MainForm outside of the sub?

    Try this:
    VB Code:
    1. (Then in the sub procedure)
    2. Private Sub cmdOK_Click()
    3. 'Open up Form2
    4.  
    5. Dim MainForm as New Form2()
    6. MainForm.Show
    7.  
    8. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width