473,386 Members | 1,748 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,386 software developers and data experts.

referencing existing object

AMC
Hi,

I know this is a simple question so please go easy on me, but anyway. I have
a class called 'Form1' that is initialized in sub main with the code:

Public Shared Sub Main()
Application.Run(New Form1)

End Sub

How do I refer to this already created class instance from inside another
class instead of creating a new instance of the class with :

Dim f As New Form1
I need to access it's methods from other classes

THanks!

Nov 20 '05 #1
4 931
* "AMC" <ab*****@netgate.net> scripsit:
I know this is a simple question so please go easy on me, but anyway. I have
a class called 'Form1' that is initialized in sub main with the code:

Public Shared Sub Main()
Application.Run(New Form1)

End Sub

How do I refer to this already created class instance from inside another
class instead of creating a new instance of the class with :

Dim f As New Form1


\\\
Public Module AppMain
Private m_AppMainForm() As MainForm

Public ReadOnly Property AppMainForm() As MainForm
Get
Return m_AppMainForm
End Get
End Property

Public Sub Main()
m_AppMainForm = New MainForm()
Application.Run(m_AppMainForm)
End Sub
End Module
///

You can access the main form from everywhere in the app by typing
'AppMain.AppMainForm'.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #2
AMC
Thanks! that worked great

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:ui**************@tk2msftngp13.phx.gbl...
* "AMC" <ab*****@netgate.net> scripsit:
I know this is a simple question so please go easy on me, but anyway. I have a class called 'Form1' that is initialized in sub main with the code:

Public Shared Sub Main()
Application.Run(New Form1)

End Sub

How do I refer to this already created class instance from inside another class instead of creating a new instance of the class with :

Dim f As New Form1


\\\
Public Module AppMain
Private m_AppMainForm() As MainForm

Public ReadOnly Property AppMainForm() As MainForm
Get
Return m_AppMainForm
End Get
End Property

Public Sub Main()
m_AppMainForm = New MainForm()
Application.Run(m_AppMainForm)
End Sub
End Module
///

You can access the main form from everywhere in the app by typing
'AppMain.AppMainForm'.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>

Nov 20 '05 #3
Cor
Hi Herfried,

You know I do not use that appmain, but this looks for me as definitly the
best I have seen until now, my compliments.

Cor
Nov 20 '05 #4
* "Cor" <no*@non.com> scripsit:
You know I do not use that appmain, but this looks for me as definitly the
best I have seen until now, my compliments.


:-)

When writing the code for the post, I was not sure if I should place
'Sub Main' in a class as a shared method or in a module, but then I
decided to use a module. So I don't have to type the 'Shared' keyword
for every member, and everything that belongs to the whole application
should (IMO) be shared. Implementing sort of singleton pattern would
work too, but in this case I decided to use the RAD approach ;-).

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #5

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

Similar topics

2
by: Simon | last post by:
Am using the following code. <script language="JavaScript1.2"> function setquantity(productindex,productquantity) { //create the reference object irefname_none = eval("document." +...
5
by: Amelyan | last post by:
I am struggling here trying to determine what is a good programming practice as far as referencing your URLs. When you use Response.Redirect, do you use 1) Hard-coded string --...
1
by: Paul Bromley | last post by:
Please help with this one - I have scoured the newsgroups for information on this, and all of the responses relate to how to refernce controls on a NEW instanc of a form and not an exitsing one. I...
2
by: Scott M. Lyon | last post by:
I'm working on using the COM Interop wrapper on an existing .NET library, to allow existing VB6 applications to call the .NET code. And I've been able to get it working in a basic sense (I can...
2
by: Michael Williams | last post by:
I would RTM, but I'm not sure exactly what to look for. Basically, I need to be able to call a variable dynamically. Meaning something like the following: - I don't want to say OBJECT.VAR...
2
by: Robin | last post by:
I have a main table that I need to delete records that arn't referenced in another. Query says I cannot delete. If I remove the reference query all deletes ok. Hope there is a way around this ?...
21
by: cmd | last post by:
I have code in the OnExit event of a control on a subform. The code works properly in this instance. If, however, I put the same code in the OnExit event of a control on a Tab Control of a main...
2
by: ccsnavy | last post by:
For some reason referencing an unbound control on an active form from a query has ceased to work correctly. While other previously existing references to unbound controls in the same form seem to...
11
by: ozTinker | last post by:
I'm sure this shouldn't be too difficult, but I lack familiarity with the MS object model. Suppose I have a table "Purchase_Orders" and a form "TEMP" which I am using to look up a customer's...
2
by: Andrus | last post by:
I need compile in-memory assembly which references to other in-memory assembly. Compiling second assembly fails with error Line: 0 - Metadata file 'eed7li9m, Version=0.0.0.0, Culture=neutral,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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,...
0
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...

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.