Call child's function from parent form

  • Thread starter Thread starter LEE
  • Start date Start date
L

LEE

I'd like to call a function of child from parent form,
there is an issue:

Form1 (parent) calls "LoadMe" Sub in Form2 (child), it
works using the codes (in Form1):
Dim frm As New Form3()
frm.LoadMe()

but fails using these codes:
Dim frm As Form ' defined as a global variable
frm = New Form3()
frm.LoadMe()

How to fix it?

Thanks
 
LEE said:
I'd like to call a function of child from parent form,
there is an issue:

Form1 (parent) calls "LoadMe" Sub in Form2 (child), it
works using the codes (in Form1):
Dim frm As New Form3()
frm.LoadMe()

but fails using these codes:
Dim frm As Form ' defined as a global variable
frm = New Form3()
frm.LoadMe()

How to fix it?

Dim frm As Form3 ' defined as a global variable
frm = New Form3()
frm.LoadMe()
 
LEE said:
I'd like to call a function of child from parent form, .. . .
Dim frm As New Form3()
frm.LoadMe()

but fails using these codes:
Dim frm As Form ' defined as a global variable
frm = New Form3()
frm.LoadMe()

Fails /how/ exactly? Exception message?
We're not [all] psychic... ;-)

If you're using Option Strict (and you should be), you might need
to type-cast Form3 into your Form variable.

Assuming that Form3 is a Windows.Forms.Form (and you're not
using Option Strict, which you should be), I would still question this
line:
Dim frm As Form ' defined as a global variable

(OK, code and comments frequently disagree, but... )
In VB.Net, this syntax can /never/ give you a Global variable.
In a VB6 module, yes, Dim is the same as Public or Global, but here,
in the Brave New World, this is the same as coding:

Private frm As Form

which will /only/ be accessible within the Module.

You /are/ using "Option Explicit On", aren't you?

HTH,
Phill W.
 
LEE said:
I'd like to call a function of child from parent form,
there is an issue:

Form1 (parent) calls "LoadMe" Sub in Form2 (child), it
works using the codes (in Form1):
Dim frm As New Form3()
frm.LoadMe()

but fails using these codes:
Dim frm As Form ' defined as a global variable
frm = New Form3()
frm.LoadMe()

instead of calling frm.loadme you would have to do

Ctype(frm, form3).Loadme

frm itself has no method named Loadme, so does not really know that load me
exists.
 
Back
Top