473,320 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Accessing public sub in startup form

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
Nov 21 '05 #1
6 1712
when instantiating child in main
frmChild.owner = me

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


"Steve Enzer" <en***@frontiernet.net> wrote in message
news:eK**************@TK2MSFTNGP14.phx.gbl...
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

Nov 21 '05 #2
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.
Nov 21 '05 #3
Steve,

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

DirectCast(me.MdiParent,frmMain).mysub

I hope this helps,

Cor
Nov 21 '05 #4
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" <en***@frontiernet.net> wrote in message
news:OZ***************@TK2MSFTNGP09.phx.gbl...
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.

Nov 21 '05 #5
Is performance better with DirectCast? Is this specific to this example or a
general rule? Preciate the response...

"Nick Malik [Microsoft]" <ni*******@hotmail.nospam.com> wrote in message
news:yp********************@comcast.com...
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" <en***@frontiernet.net> wrote in message
news:OZ***************@TK2MSFTNGP09.phx.gbl...
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.


Nov 21 '05 #6
Clamps,

General rule, although the optimizing seems to do a lot with the Ctype
(Convert Type).

Directcast is using as
CType is converting to or using as

Cor
Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Matt Smolic | last post by:
02.06.04 I need some help displaying a public variable on a form. The variable is declared and initilazied in a module at startup (and declared Public). I have verified this with a...
1
by: cefrancke | last post by:
I have set the Startup properties to the following... All menus, toolbars, etc are turned off plus these are unchecked Allow Full Menus Allow Built-in Toolbars Allow Default Shortcut Menus...
2
by: cm | last post by:
HI, here's my problem; My application loads up 3 forms at startup. Deppending on what button is press on form1 i want to show or hide controls on form2. I cant seem to get access to the...
3
by: Vivek Sharma | last post by:
Hi, I have created a dropdownlist as a web user control. I am using its multiple instances on the webpage. How do I access the selectedValue of each instance? All the instances have different...
1
by: tmaster | last post by:
Within a class, can I create a property that is a listview? Here's what I tried, but it doesn't seem to work: '------------ create property to give the second form access to the first form's...
1
by: David L Wright II | last post by:
I am trying to access a mdi parent form's properties and methods outside of the mdi parent form's class module. I keep getting "Reference to a non-shared member requires an object reference"...
2
by: Steve Enzer | last post by:
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...
3
by: DotNetNewbie | last post by:
I am reading the book Teach Yourself Microsoft Visual Basic .Net 2003 in 21 Days. I am having trouble getting one of the exercises to work at the end of day 4. Exercises: 1. Create a new...
3
by: Olivier BESSON | last post by:
Hello, I have a web service of my own on a server (vb.net). I must declare it with SoapRpcMethod to be used with JAVA. This is a simple exemple method of my vb source : ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.