473,795 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1732
when instantiating child in main
frmChild.owner = me

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


"Steve Enzer" <en***@frontier net.net> wrote in message
news:eK******** ******@TK2MSFTN GP14.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).TestBo x()

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.NullRef erenceException ' 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.M diParent,frmMai n).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***@frontier net.net> wrote in message
news:OZ******** *******@TK2MSFT NGP09.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).TestBo x()

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.NullRef erenceException ' 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*******@hotm ail.nospam.com> wrote in message
news:yp******** ************@co mcast.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***@frontier net.net> wrote in message
news:OZ******** *******@TK2MSFT NGP09.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).TestBo x()

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.NullRef erenceException ' 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
1499
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 msgBox(dbprogram) call. When I try to display it in the form in a text box I get a #Name? error instead. I was told I have to write a function to display it. I wrote a public function in the startup module to return the value of a given string variable. Below...
1
11322
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 Allow Toolbar/Menu Changes Use Access Special Keys
2
2285
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 controls on from2 to hide them unless i create another instance from within form1 which i dont want to do. i just want to use the one creted when the program starts up. Any ideas?
3
2796
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 IDs. Thanks Vivek
1
1836
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 listview: Public Class frmToDoDetail ' (this is the second form)
1
1525
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" compiler error. The mdi parent form is the startup object. I should be able to access the startup object in my other modules, but I cannot find the startup object's name. Does anyone have suggestions?
2
1304
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 appearance of the toolbar under certain conditions. So far I have not figured out how to reference the sub from another form. One member of this group suggested I use the statement: CType(Me.Owner, frmMain).tbMainReset() where "tbMainReset" is...
3
2186
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 multiple-form application that displays two forms when it starts, each with a text box. Add code to each text box’s TextChanged event (this is the
3
5006
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 : >************************************************************************ > <WebMethod(), System.Web.Services.Protocols.SoapRpcMethod()> _ > Public Function HelloWorld() As > <System.Xml.Serialization.SoapElementAttribute("return")> String
0
9673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10448
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10217
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10167
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9046
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7544
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6784
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5440
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2922
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.