473,769 Members | 3,232 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Startup Form's Name

This is probably a silly question, but I've gotten myself confused.

My app has two forms, form1 and form2. form1 is the start up object in the
propers. An event in form1 instantiates form2.

Dim myForm as HardwareStore
myForm = New HardwareStore
myForm.Show()

I understand that my form2 can be referenced by

myForm.blah

What is the form name for form1 so that I can reference it from form2
(myForm)?

form1.blah

Doesn't work.

Sorry for such a basic question, but I'm trying to learn here, hahaha.

Bernie
Apr 6 '06 #1
10 3002

You really don't have two forms. You have a form class 'HardwareStore'
and an instance of that class 'myForm'.

When setting a startup object you would select HardwareStore and the
runtime will generate an instance of it and display that instance. You
need to explictly create and show the form.

Depending upon where the lines above are placed either they will never
be run or you may have two instances of HardwareStore showing.
There are a few different ways to start a VB.Net application.

For a simple start.
Define the HardwareStore form. Mark it as your startup object. Run the
application and it will show.

For a more complicated start.
Create a module, say HardwareLoader, and put a sub main() in it
Module HardwareLoader

public sub main(args() as string)

Dim mainForm as new HardwareStore
Application.Run (mainForm)

end sub

end module
Set HardwareLoader as the startup object. Run application.
hth,
Alan.

Apr 6 '06 #2
You can set a property in Form 2 such as myform1 and set to the startup form
as;

dim myform2 as nrew form2
myform2.myform1 = me
myform2.show or myform2.showdia log

--
Dennis in Houston
"Bernie Hunt" wrote:
This is probably a silly question, but I've gotten myself confused.

My app has two forms, form1 and form2. form1 is the start up object in the
propers. An event in form1 instantiates form2.

Dim myForm as HardwareStore
myForm = New HardwareStore
myForm.Show()

I understand that my form2 can be referenced by

myForm.blah

What is the form name for form1 so that I can reference it from form2
(myForm)?

form1.blah

Doesn't work.

Sorry for such a basic question, but I'm trying to learn here, hahaha.

Bernie

Apr 6 '06 #3
Following your guidelines, I now have;

Module Main
Public Sub main()
Dim myFormStartup As New StartUp
Application.Run (myFormStartup)
End Sub

Class Startup
Dim myFormHardware As Hardware_Store
Dim myFormHardwareS tatus As Boolean

Private Sub StartUp_Load(By Val sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
myFormHardwareS tatus = False
End Sub

Private Sub StartUp_Load(By Val sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
myFormHardwareS tatus = False
myFormHardware = New Hardware_Store
myFormHardware. Show()

End Sub

Public Function getMyFormHardwa reStatus() As Boolean
Return myFormHardwareS tatus
End Function

Public Sub setMyFormHardwa reStatus(ByVal Status As Boolean)
myFormHardwareS tatus = Status
End Sub
Class HardwareStore
Private Sub Hardware_Store_ Load(ByVal sender As System.Object, ByVal
e As System.EventArg s) Handles MyBase.Load
' This line is where I'm having the problem
' The error says MyFormStartup is not declared

myFormStartup.s etMyFormHardwar eStatus(True)

End Sub

The problem is trying to reference a function or sub in the myFormStartup
that I instantiated in the sub Main().

What am I missing to be able to access a function in myFormStartup?

Thanks,
Bernie


"AlanT" <al*******@user s.com> wrote in news:1144283866 .510955.33080
@i39g2000cwa.go oglegroups.com:

You really don't have two forms. You have a form class 'HardwareStore'
and an instance of that class 'myForm'.

When setting a startup object you would select HardwareStore and the
runtime will generate an instance of it and display that instance. You
need to explictly create and show the form.

Depending upon where the lines above are placed either they will never
be run or you may have two instances of HardwareStore showing.
There are a few different ways to start a VB.Net application.

For a simple start.
Define the HardwareStore form. Mark it as your startup object. Run the
application and it will show.

For a more complicated start.
Create a module, say HardwareLoader, and put a sub main() in it
Module HardwareLoader

public sub main(args() as string)

Dim mainForm as new HardwareStore
Application.Run (mainForm)

end sub

end module
Set HardwareLoader as the startup object. Run application.
hth,
Alan.


Apr 6 '06 #4
Bernie,

It is not impossible. However you would try to avoid it. It can make your
project completely dependend from form2. If you change something in that
than you have forever to think that it can have effects on form1. And with
that ending one of one of the major reasons of OOP. Maintainability .

You should not try to do things in your class Form2, which are done in
Form1. Create than a special class for that, which you can use in both.

Just my thought,

Cor

"Bernie Hunt" <bh***@optonlin e.net> schreef in bericht
news:Xn******** *************** ********@207.46 .248.16...
This is probably a silly question, but I've gotten myself confused.

My app has two forms, form1 and form2. form1 is the start up object in the
propers. An event in form1 instantiates form2.

Dim myForm as HardwareStore
myForm = New HardwareStore
myForm.Show()

I understand that my form2 can be referenced by

myForm.blah

What is the form name for form1 so that I can reference it from form2
(myForm)?

form1.blah

Doesn't work.

Sorry for such a basic question, but I'm trying to learn here, hahaha.

Bernie

Apr 6 '06 #5

It looks like there was some misunderstandin g on my part.

My interpretation was that you have one form HardwareStore class that
is your application.

from the above code you have 2
StartUp
Hardware_Store
What does startup do?
Do you need it?

Can you just replace Startup in main() with Hardware_Store?
Alan.

Apr 6 '06 #6
The example I sent is a cut down version to show the problem. The startup
form contains buttons that will launch other programs. HardwareStore is
just one of them.

The issue is my syntax to call a function between the Startup form and
HardwareStore form. I can get the forms instatuated OK, I stuck at the
newbie point of how does one of them call a function from the other.

Sorry for such a silly problem, but I must be missing something basic.

Bernie
"AlanT" <al*******@user s.com> wrote in news:1144330236 .703603.148880
@u72g2000cwu.go oglegroups.com:

It looks like there was some misunderstandin g on my part.

My interpretation was that you have one form HardwareStore class that
is your application.

from the above code you have 2
StartUp
Hardware_Store
What does startup do?
Do you need it?

Can you just replace Startup in main() with Hardware_Store?
Alan.


Apr 6 '06 #7
Cor,

I understand and your point makes alot of sense. The basic problem will
still exist in your suggested design.

The problem is I'm having trouble accessing a function in an instatiated
form. Please see the code I posted in my other message. I show the exact
problem there.

If I can get past the amazinly simple syntax problem, then I can worry
about better design, hahahaha.

Bernie
"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in
news:eM******** *****@TK2MSFTNG P03.phx.gbl:
Bernie,

It is not impossible. However you would try to avoid it. It can make
your project completely dependend from form2. If you change something
in that than you have forever to think that it can have effects on
form1. And with that ending one of one of the major reasons of OOP.
Maintainability .

You should not try to do things in your class Form2, which are done in
Form1. Create than a special class for that, which you can use in
both.

Just my thought,

Cor

"Bernie Hunt" <bh***@optonlin e.net> schreef in bericht
news:Xn******** *************** ********@207.46 .248.16...
This is probably a silly question, but I've gotten myself confused.

My app has two forms, form1 and form2. form1 is the start up object
in the propers. An event in form1 instantiates form2.

Dim myForm as HardwareStore
myForm = New HardwareStore
myForm.Show()

I understand that my form2 can be referenced by

myForm.blah

What is the form name for form1 so that I can reference it from form2
(myForm)?

form1.blah

Doesn't work.

Sorry for such a basic question, but I'm trying to learn here,
hahaha.

Bernie


Apr 6 '06 #8
You need access to the instance of the StartUp form. myFormStartup that you
defined in Sub Main is local to that method and not acessable from any other
place. You HardwareStore class (or is it Hardware_Store? ) needs to be
provided with a reference to the StartUp form instance. There are several
ways to do this. One of the easiest ways is to add a parameter to the
constructor of HardwareStore and pass a reference that way

Class HardwareStore
Private myStartUpForm as StartUp
Public Sub New(ByVal StartUpForm As StartUp)
' Save the reference to StartUp for later use
myStartUpForm = StartUpForm
End

Public Function getMyFormHardwa reStatus() As Boolean
Return myStartUpForm.m yFormHardwareSt atus
End Function

Public Sub setMyFormHardwa reStatus(ByVal Status As Boolean)
myStartUpForm.m yFormHardwareSt atus = Status
End Sub
End Class
....
Private Sub StartUp_Load(By Val sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
myFormHardwareS tatus = False
' Pass a reference to this instance of StartUp to the new HardwareStore
instance
myFormHardware = New HardwareStore(M e)
myFormHardware. Show()
End Sub

You need to change myFormHardwareS tatus to be Public (or preferable to a
property)

/claes
"Bernie Hunt" <bh***@optonlin e.net> wrote in message
news:Xn******** *************** *******@207.46. 248.16...
Following your guidelines, I now have;

Module Main
Public Sub main()
Dim myFormStartup As New StartUp
Application.Run (myFormStartup)
End Sub

Class Startup
Dim myFormHardware As Hardware_Store
Dim myFormHardwareS tatus As Boolean

Private Sub StartUp_Load(By Val sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
myFormHardwareS tatus = False
End Sub

Private Sub StartUp_Load(By Val sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
myFormHardwareS tatus = False
myFormHardware = New Hardware_Store
myFormHardware. Show()

End Sub

Public Function getMyFormHardwa reStatus() As Boolean
Return myFormHardwareS tatus
End Function

Public Sub setMyFormHardwa reStatus(ByVal Status As Boolean)
myFormHardwareS tatus = Status
End Sub
Class HardwareStore
Private Sub Hardware_Store_ Load(ByVal sender As System.Object, ByVal
e As System.EventArg s) Handles MyBase.Load
' This line is where I'm having the problem
' The error says MyFormStartup is not declared

myFormStartup.s etMyFormHardwar eStatus(True)

End Sub

The problem is trying to reference a function or sub in the myFormStartup
that I instantiated in the sub Main().

What am I missing to be able to access a function in myFormStartup?

Thanks,
Bernie


"AlanT" <al*******@user s.com> wrote in news:1144283866 .510955.33080
@i39g2000cwa.go oglegroups.com:

You really don't have two forms. You have a form class 'HardwareStore'
and an instance of that class 'myForm'.

When setting a startup object you would select HardwareStore and the
runtime will generate an instance of it and display that instance. You
need to explictly create and show the form.

Depending upon where the lines above are placed either they will never
be run or you may have two instances of HardwareStore showing.
There are a few different ways to start a VB.Net application.

For a simple start.
Define the HardwareStore form. Mark it as your startup object. Run the
application and it will show.

For a more complicated start.
Create a module, say HardwareLoader, and put a sub main() in it
Module HardwareLoader

public sub main(args() as string)

Dim mainForm as new HardwareStore
Application.Run (mainForm)

end sub

end module
Set HardwareLoader as the startup object. Run application.
hth,
Alan.

Apr 6 '06 #9

You will need to include a reference to the startup form in the
HardwareStore et al.

A way is to create a base form from which to derive all you Store forms
and include in that a property parent

e.g.

Public class StoreBase
inherits System.Windows. Forms.Form

....

Public property ParentForm() as Form
Get
return _parentForm
end get
Set (value as Form)
_parentForm = value
end set
end property
private _parentForm as Form

...

end class
In Startup when you launch the store use

Dim hardware as New HardwareStore
hardware.Parent Form = me
hardware.Show()
Hardware (and all the other apps)

public class HardwareStore
inherits StoreBase
' some code that references startup

private Sub DoSomething()

ParentForm.xxx( )

end sub

end class

hth,
Alan.

Apr 6 '06 #10

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

Similar topics

2
336
by: Imayakumar | last post by:
Hi, I got two forms, named Form1 and Form2 ion a VB.NET Windows application.. by default if i run the application, Form1 gets launched..i need to set Form2 as the startup form how do i do it?? Thanks. Imaya Kumar J.
5
2798
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 http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
3
3050
by: Douglas Buchanan | last post by:
Buttons don't work if form is opened on startup A2k If 'frmMain' is set to open by default at startup none of the buttons work. If 'frmMain' is opened from the database window then all the buttons work. The form's name ('frmMain') is selected from in the Startup dialog box.
1
5377
by: John Michael | last post by:
I have created some password routines to protect certain forms from access without a password. This allows me to create some security for apps that will be used on diff machines for users that will not have to learn the whole access security process and me as well. I would like to lockup my database by unchecking all of the options in the tools/startup from. I know i can create custom menus, toolbars and command bars and add a link to...
7
6899
by: cefrancke | last post by:
I cant seem to find a straight answer on the following. I want to programmatically hide all menus except a basic custom report menu (during report preview) and right click pop-up A-Z sorting on datasheets (for subforms). I would like to do this on startup of the application. To be clear:
1
11321
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
8
26793
by: Brian Fulford | last post by:
This is my first shot at a Winforms application in dot net. This application is mainly going to run unattended but is using a form to display current activity of the background processing. In VB6, I could set the startup to be Sub Main and then call frmMain.Show and the program would continue processing; however, after instantiating the from in VB.Net - dim frmMain as new frmMain, frmMain.show shows the form then closes the form to continue...
4
3908
by: Chris Ashley | last post by:
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:
10
22378
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 progress of these tasks on a label on the SplashScreen form. Once this is completed ok, the splash screen should close and the login form should be displayed. A successful login closes that form and shows the main form.
0
9590
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
9424
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10223
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
10051
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...
0
8879
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
7413
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
5310
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...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2815
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.