[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.
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:
Dim nfrm As New Form
Dim cfrm As New Form
Those two objects are never used because you simply discard them in the next two lines:
vb Code:
nfrm = NForm
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:
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:That first block of code should be rewritten like this:
vb Code:
Public Sub Load_Form(ByVal NForm As Form, ByVal CForm As Form)
NForm.MdiParent = CForm.MdiParent
NForm.Show()
CForm.Close()
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.
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