PC Review


Reply
Thread Tools Rate Thread

Call child's function from parent form

 
 
LEE
Guest
Posts: n/a
 
      17th Dec 2003
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


 
Reply With Quote
 
 
 
 
Armin Zingler
Guest
Posts: n/a
 
      17th Dec 2003
"LEE" <(E-Mail Removed)> schrieb
> 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()



--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

 
Reply With Quote
 
Phill. W
Guest
Posts: n/a
 
      17th Dec 2003
"LEE" <(E-Mail Removed)> wrote in message
news:0a8501c3c4a9$1a517910$(E-Mail Removed)...
> 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.


 
Reply With Quote
 
CJ Taylor
Guest
Posts: n/a
 
      17th Dec 2003

"LEE" <(E-Mail Removed)> wrote in message
news:0a8501c3c4a9$1a517910$(E-Mail Removed)...
> 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.



> How to fix it?
>
> Thanks
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Call a parent form function when the child is closing dave b via AccessMonster.com Microsoft Access Form Coding 1 6th Apr 2006 06:00 PM
Call an event handler on a parent form from child form jimcolli@pacbell.net Microsoft C# .NET 3 20th Jan 2006 02:32 AM
Re: HOW DO ON CLICK OF BUTTON IN MDI PARENT I CALL A FUNCTION IN CHILD FORM Herfried K. Wagner [MVP] Microsoft VB .NET 0 17th Nov 2004 12:12 PM
Call Sub on Parent form from Child Form =?Utf-8?B?QnJpYW5ESA==?= Microsoft VB .NET 5 4th Nov 2004 09:52 PM
Re: HOW DO ON CLICK OF BUTTON IN MDI PARENT I CALL A FUNCTION IN CHILD FORM Herfried K. Wagner [MVP] Microsoft VB .NET 0 17th Oct 2004 11:47 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:58 PM.