PC Review


Reply
Thread Tools Rate Thread

Accessing public sub in startup form

 
 
Steve Enzer
Guest
Posts: n/a
 
      19th Aug 2005
My project uses a MDI parent form and several child forms. I need to call a
public sub in the parent form (which is also the startup object) from one of
the child forms in order to change the appearance of the toolbar under
certain conditions. So far I have not figured out how to reference the sub
from another form. I figure I need the object name of the startup form, but
since I don't declare this in code as I do the other forms, I haven't been
able to find what this is. Using the class name ("frmMain") doesn't work.

Thanks for any advice.
Steve Enzer


 
Reply With Quote
 
 
 
 
Clamps
Guest
Posts: n/a
 
      19th Aug 2005
when instantiating child in main
frmChild.owner = me

when needing to call sub from child
ctype(me.owner, frmMain).subToExecute






"Steve Enzer" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> My project uses a MDI parent form and several child forms. I need to call

a
> public sub in the parent form (which is also the startup object) from one

of
> the child forms in order to change the appearance of the toolbar under
> certain conditions. So far I have not figured out how to reference the

sub
> from another form. I figure I need the object name of the startup form,

but
> since I don't declare this in code as I do the other forms, I haven't been
> able to find what this is. Using the class name ("frmMain") doesn't work.
>
> Thanks for any advice.
> Steve Enzer
>
>



 
Reply With Quote
 
Steve Enzer
Guest
Posts: n/a
 
      20th Aug 2005
Thanks for your advice, but I'm getting an error with the code you
suggested.

I'm using the statement:
CType(Me.Owner, frmMain).TestBox()

to call the public subroutine TestBox in frmMain. When I test the code I
get an exception with the message:

"An unhandled exception of type 'System.NullReferenceException' occurred in
Project Manager.exe

Additional information: Object reference not set to an instance of an
object."

What do I try next? I'm a VB6 programmer trying to start a new project in
VB .NET 2003 and I'm still on the steep part of the learning curve.


 
Reply With Quote
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      20th Aug 2005
Steve,

Use mdiParent instead of Owner in Champs advice or even very slightly
better.

DirectCast(me.MdiParent,frmMain).mysub

I hope this helps,

Cor


 
Reply With Quote
 
Nick Malik [Microsoft]
Guest
Posts: n/a
 
      20th Aug 2005
Your 'Owner' property is not set to a value. To use this techique, you'd
need to set the Owner property after creating the child form. Can you post
the code that does that?

(btw: Cor's technique is better, IMHO)

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"Steve Enzer" <(E-Mail Removed)> wrote in message
news:OZd%(E-Mail Removed)...
> Thanks for your advice, but I'm getting an error with the code you
> suggested.
>
> I'm using the statement:
> CType(Me.Owner, frmMain).TestBox()
>
> to call the public subroutine TestBox in frmMain. When I test the code I
> get an exception with the message:
>
> "An unhandled exception of type 'System.NullReferenceException' occurred
> in Project Manager.exe
>
> Additional information: Object reference not set to an instance of an
> object."
>
> What do I try next? I'm a VB6 programmer trying to start a new project in
> VB .NET 2003 and I'm still on the steep part of the learning curve.
>
>



 
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
Accessing Public Folders =?Utf-8?B?bGF1cmVubQ==?= Microsoft Outlook Discussion 1 13th Sep 2006 09:03 PM
accessing public folders =?Utf-8?B?Z29kdWNrcw==?= Microsoft Outlook Calendar 1 10th Feb 2005 03:54 AM
NEWBIE - Accessing a public variable that is stored in another form's vb code Dave Microsoft Dot NET Compact Framework 1 18th Jan 2005 08:55 PM
Quest: Accessing parent form's public data member... lewi Microsoft C# .NET 2 10th Nov 2003 03:52 PM
Re: Accessing 2 PC's over Public Network Jeffrey Randow (MVP) Windows XP Work Remotely 0 31st Jul 2003 02:10 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:09 PM.