|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Startup Form's NameMy 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 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. 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 myFormHardwareStatus As Boolean Private Sub StartUp_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load myFormHardwareStatus = False End Sub Private Sub StartUp_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load myFormHardwareStatus = False myFormHardware = New Hardware_Store myFormHardware.Show() End Sub Public Function getMyFormHardwareStatus() As Boolean Return myFormHardwareStatus End Function Public Sub setMyFormHardwareStatus(ByVal Status As Boolean) myFormHardwareStatus = Status End Sub Class HardwareStore Private Sub Hardware_Store_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ' This line is where I'm having the problem ' The error says MyFormStartup is not declared myFormStartup.setMyFormHardwareStatus(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" <alanto***@users.com> wrote in news:1144283866.510955.33080 @i39g2000cwa.googlegroups.com:Show quoteHide quote > > 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. > It looks like there was some misunderstanding 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. 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" <alanto***@users.com> wrote in news:1144330236.703603.148880 @u72g2000cwu.googlegroups.com:Show quoteHide quote > > It looks like there was some misunderstanding 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. > > 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.ParentForm = 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. 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 getMyFormHardwareStatus() As Boolean Return myStartUpForm.myFormHardwareStatus End Function Public Sub setMyFormHardwareStatus(ByVal Status As Boolean) myStartUpForm.myFormHardwareStatus = Status End Sub End Class .... Private Sub StartUp_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load myFormHardwareStatus = False ' Pass a reference to this instance of StartUp to the new HardwareStore instance myFormHardware = New HardwareStore(Me) myFormHardware.Show() End Sub You need to change myFormHardwareStatus to be Public (or preferable to a property) /claes Show quoteHide quote "Bernie Hunt" <bh***@optonline.net> wrote in message news:Xns979DC1ACE914bhuntoptonlinenet@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 myFormHardwareStatus As Boolean > > Private Sub StartUp_Load(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles MyBase.Load > myFormHardwareStatus = False > End Sub > > Private Sub StartUp_Load(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles MyBase.Load > myFormHardwareStatus = False > myFormHardware = New Hardware_Store > myFormHardware.Show() > > End Sub > > Public Function getMyFormHardwareStatus() As Boolean > Return myFormHardwareStatus > End Function > > Public Sub setMyFormHardwareStatus(ByVal Status As Boolean) > myFormHardwareStatus = Status > End Sub > > > Class HardwareStore > Private Sub Hardware_Store_Load(ByVal sender As System.Object, ByVal > e As System.EventArgs) Handles MyBase.Load > ' This line is where I'm having the problem > ' The error says MyFormStartup is not declared > > myFormStartup.setMyFormHardwareStatus(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" <alanto***@users.com> wrote in news:1144283866.510955.33080 > @i39g2000cwa.googlegroups.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. >> > 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.showdialog -- Show quoteHide quoteDennis 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 > 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 Show quoteHide quote "Bernie Hunt" <bh***@optonline.net> schreef in bericht news:Xns979CCF2108ABAbhuntoptonlinenet@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 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 Show quoteHide quote "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in news:eMwvLSUWGHA.924@TK2MSFTNGP03.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***@optonline.net> schreef in bericht > news:Xns979CCF2108ABAbhuntoptonlinenet@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 > > > Bernie,
You want to share a function between two forms. That the function is now on form1 is in my idea from not any importancy. It can be a good reason to make a shared class as this function has as well data in it. If it has not data than it is bettter just to instance it when it is needed. Therefore we get something as Class Form1 etc Sub Whatever MyHelperClass.myStatus = true end sub Class Form2 ect Sub Whatever dim status = myHelperClass.MyStatus end sub Public Class myHelperClass public shared MyTogle as boolean Public Shared property MyStatus() as boolean Get return MyTogle End Get Set(byval value as boolean) myTogle = value End Set End Class I hope that this gives an idea Cor Show quoteHide quote "Bernie Hunt" <bh***@optonline.net> schreef in bericht news:Xns979D6898E725Dbhuntoptonlinenet@207.46.248.16... > 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]" <notmyfirstn***@planet.nl> wrote in > news:eMwvLSUWGHA.924@TK2MSFTNGP03.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***@optonline.net> schreef in bericht >> news:Xns979CCF2108ABAbhuntoptonlinenet@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 >> >> >> > >
populating variables from dynamically created controls
Drawing xor lines how do I customize a vb.net deployment project Mixing languages in one assembly multiple selection from checkboxes into text box Inherited UserControls do not in appear in Toolbox (VB.NET 2005) Visual Basic 2005 Express SQL Server Locks/ProcessID - Is this a problem? Textbox 'remembering' previous entries A form that returns a value |
|||||||||||||||||||||||