Results 1 to 3 of 3

Thread: [02/03] load form user defined procedure

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2007
    Posts
    403

    [02/03] load form user defined procedure

    hi all,

    i'm having a problem with this procedure.. it normally calls a form without any parameter and it works fine... but then, i needed to put parameters whenever i call another form and i got a bit of a problem.

    the procedure below to call a form without passing a parameter works.
    Code:
        Public Sub Load_Form(ByVal NForm As Form, ByVal CForm As Form)
            Dim nfrm As New Form
            Dim cfrm As New Form
    
            nfrm = NForm
            cfrm = CForm
            nfrm.MdiParent = cfrm.MdiParent
            nfrm.Show()
            cfrm.Close()
        End Sub
    this code here seems to be having lots of problems.
    Code:
        Public Sub Load_Form(ByVal NForm As Form(), ByVal CForm As Form)
            Dim nfrm As New Form(myParam)
            Dim cfrm As New Form
    
            nfrm = NForm()
            cfrm = CForm
            nfrm.MdiParent = cfrm.MdiParent
            nfrm.Show()
            cfrm.Close()
        End Sub
    any suggestions? thanks.

    VB Version: Microsoft Visual Studio 2008 Professional Edition
    .NET Version: Microsoft .NET Framework Version 3.5
    OS: Windows XP SP3

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [02/03] load form user defined procedure

    You have numerous issues there. First let's look at the first block of code. These lines create two new Form objects:
    vb Code:
    1. Dim nfrm As New Form
    2. Dim cfrm As New Form
    Those two objects are never used because you simply discard them in the next two lines:
    vb Code:
    1. nfrm = NForm
    2. cfrm = CForm
    Why create two forms if you're never going to use them?

    Now on to your second block of code. First of all that method is expecting an array of Forms to be passed to that first argument, not a single Form. That's what the parentheses mean:
    Code:
    Public Sub Load_Form(ByVal NForm As Form(), ByVal CForm As Form)
    Secondly, the constructor for the Form class has no arguments this is not legal syntax:
    vb Code:
    1. Dim nfrm As New Form(myParam)
    Even if it was though, the two Form objects you create in the first two lines are simply discarded again in the next two lines. Apart from that, this is not legal syntax either:
    vb Code:
    1. nfrm = NForm()
    That first block of code should be rewritten like this:
    vb Code:
    1. Public Sub Load_Form(ByVal NForm As Form, ByVal CForm As Form)
    2.         NForm.MdiParent = CForm.MdiParent
    3.         NForm.Show()
    4.         CForm.Close()
    5.     End Sub
    The second block has no hope I'm afraid. Because your arguments are type Form you cannot access any members other than those inherited from the Form class. If you know what type they will be then use that type instead of Form, otherwise you're up the creek essentially.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2007
    Posts
    403

    Re: [02/03] load form user defined procedure

    i had a different procedure initially but it didnt work... you can refer to this thread to know why i needed to do that... http://www.vbforums.com/showthread.php?t=481244

    VB Version: Microsoft Visual Studio 2008 Professional Edition
    .NET Version: Microsoft .NET Framework Version 3.5
    OS: Windows XP SP3

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