473,221 Members | 2,205 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,221 software developers and data experts.

Getting a reference to the startup form?

I have a class called App set as the startup object with the following code:

Friend Class App
Shared Sub Main()
Dim FrmMain As New MainForm
Application.Run(FrmMain)
End Sub
End Class

In another form I use the following code:

Private Sub AddCustomer_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
FrmMain.Text = "Add Customer"
End Sub

I get the error that FrmMain is not declared. Didn't I get a reference to it
called FrmMain in my Sub Main? How else can I get a reference to the startup
form?

Regards,

Chris
Nov 21 '05 #1
4 3864
Chris,

I never use that classic startup method you show as something extra however
VB6 and C diehards like it.

Your mainform can in VBNet be the startup object it needs nothing more than
that you do not change the application settings and keep it with the name of
that form (class).

However there is nothing wrong with changing the name of that object and
than you have to change the startup object in the application properties.
(When you rename it, that goes not automaticly what you would suspect)

Solution explorere -> Application right click -> properties -> Startup
object and set the startup form.

I hope this helps?

Cor
Nov 21 '05 #2

"Chris Ashley" <ch**********@SPAMblueyonder.co.uk> wrote in message
news:416ce78a.0@entanet...
I have a class called App set as the startup object with the following
code:

Friend Class App
Shared Sub Main()
Dim FrmMain As New MainForm
Application.Run(FrmMain)
End Sub
End Class

In another form I use the following code:

Private Sub AddCustomer_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
FrmMain.Text = "Add Customer"
End Sub

I get the error that FrmMain is not declared. Didn't I get a reference to
it called FrmMain in my Sub Main? How else can I get a reference to the
startup form?

Regards,

Chris


I sorted this by using a shared property in my startup class. Here's the
code I'm using now:

Public Class App
Private Shared m_FrmMain As MainForm
Public Shared Property FrmMain() As MainForm
Get
Return m_FrmMain
End Get
Set(ByVal Value As MainForm)
m_FrmMain = Value
End Set
End Property
<STAThread()> _
Shared Sub Main()
Dim FrmStart As New MainForm
FrmMain = FrmStart
FrmMain.ShowDialog()
End Sub
End Class

Now I can access my main form through App.FrmMain - was this the right way
to do this?

Regards,

Chris
Nov 21 '05 #3
Hi,

You declared frmMain inside a subroutine. It is only available in
the subroutine.

Ken
--------------------
"Chris Ashley" <ch**********@SPAMblueyonder.co.uk> wrote in message
news:416ce78a.0@entanet...
I have a class called App set as the startup object with the following code:

Friend Class App
Shared Sub Main()
Dim FrmMain As New MainForm
Application.Run(FrmMain)
End Sub
End Class

In another form I use the following code:

Private Sub AddCustomer_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
FrmMain.Text = "Add Customer"
End Sub

I get the error that FrmMain is not declared. Didn't I get a reference to it
called FrmMain in my Sub Main? How else can I get a reference to the startup
form?

Regards,

Chris

Nov 21 '05 #4
"Chris Ashley" <ch**********@SPAMblueyonder.co.uk> schrieb:
I have a class called App set as the startup object with the
following code:

Friend Class App
Shared Sub Main()
Dim FrmMain As New MainForm
Application.Run(FrmMain)
End Sub
End Class

In another form I use the following code:

Private Sub AddCustomer_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
FrmMain.Text = "Add Customer"
End Sub

I get the error that FrmMain is not declared.


Providing a reference to an application’s main form
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=accessmainform>

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

Nov 21 '05 #5

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

Similar topics

2
by: Zippy | last post by:
Some months ago, we requested help from this newsgroup on how to replace the library reference of a database with another library reference, prior to creating an MDE. I got the following answer...
5
by: mark s | last post by:
How can I make a checkbox that says "Do not show this again at startup" on my reminder form? Thanks! -- name: Mark S. email: huskie_009@hotmail.com *** Sent via Developersdex...
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...
4
by: Tony Vitonis | last post by:
Hello. I've written an app that I want to "live" in the system tray. I want it to start up with just a tray icon showing, and if the user selects "Settings..." from the icon's context menu, to...
2
by: Mark D | last post by:
Hi Relative vb.net newbie here... I have a Windows Form application with a few subroutines in a separate module. From one of the subroutines, I want to get the value of a label or text box on...
4
by: Johnnie Miami | last post by:
I'm using VB.Net 2005 beta 2 and have my login form (login.vb) specified as the startup form. If the user is successful logging in, I call my main form (main.vb). This all works fine but the...
4
by: John Mishefske | last post by:
I have a "Tracker" class that registers "Messenger" classes to allow distribution of unicast and broadcast messages between instances. In code a reference to the Tracker class instance is...
10
by: =?Utf-8?B?UmljaGFyZCBCeXNvdXRo?= | last post by:
Hi In my app I have a SplashScreen, a login form and a main form. On launching the app, I'd like to show the SplashScreen while reading config files and attempting a database connection. I show...
11
by: Hotrod2000 | last post by:
I'm quite new to programming but I'm having problems getting a timer to work in visual studio.net I've created a timer on a form, enabled it and then typed the following code (from the mdsn...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...

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.