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

Home Posts Topics Members FAQ

Error Module level form obj Mltiple forms

Bob
Declaring a module level form object in multiple froms
within a project to show another project form causes a
stack overflow and other assorted errors. Can anyone help?
Jul 21 '05 #1
6 1911
Bob,
Sounds like spaghetti? :-)

Can you post a sample of what you are doing? Along with which routine you
were calling when you got the stack overflow.

Hope this helps
Jay

"Bob" <ir*****@arc.lo srios.edu> wrote in message
news:08******** *************** *****@phx.gbl.. .
Declaring a module level form object in multiple froms
within a project to show another project form causes a
stack overflow and other assorted errors. Can anyone help?

Jul 21 '05 #2
Bob
Jay,

The project has two forms with nothing on either of them.

Code in Form 1
------------------------------------------
Public Class Form1
Inherits System.Windows. Forms.Form
'Windows Form Designer generated code
Dim objForm2 As New Form2()
End Class
-------------------------------------------
Code in Form2
-------------------------------------------
Public Class Form2
Inherits System.Windows. Forms.Form
'Windows Form Designer generated code
Dim objForm1 As New Form1()
End Class
-------------------------------------------

When I build the project (version 2002 or 2003), I get a
stack overflow.
-----Original Message-----
Bob,
Sounds like spaghetti? :-)

Can you post a sample of what you are doing? Along with which routine youwere calling when you got the stack overflow.

Hope this helps
Jay

"Bob" <ir*****@arc.lo srios.edu> wrote in message
news:08******* *************** ******@phx.gbl. ..
Declaring a module level form object in multiple froms
within a project to show another project form causes a
stack overflow and other assorted errors. Can anyone
help?

.

Jul 21 '05 #3
Bob,
You are using object initialization syntax. Which is causing your problems.

When you create a new Form1 a new form2 gets created, when a new form2 gets
created a new form1 gets created, which causes a new form2, which causes a
new form1, which will go on until you run out of stack space.

Change these two lines:
Dim objForm1 As New Form1() Dim objForm2 As New Form2()
To:
Dim objForm1 As Form1
Dim objForm2 As Form2
Now the problem becomes how to initialize the variables. Normally I pass an
instance of the object to the constructor of the form (add an overloaded Sub
New). Unfortunately this will not work in this case as you have two forms
that mutually refer to each other. In that case I normally have the second
object accept the first as a parameter to the constructor, in the constuctor
of the second I call a property of the first to set the reference to the
second.

Out of curiosity: What are you attempting to do, that you have each form
refer to the other? I suspect a Singleton Pattern might be a better
approach.

Hope this helps
Jay
"Bob" <ir*****@arc.lo srios.edu> wrote in message
news:01******** *************** *****@phx.gbl.. . Jay,

The project has two forms with nothing on either of them.

Code in Form 1
------------------------------------------
Public Class Form1
Inherits System.Windows. Forms.Form
'Windows Form Designer generated code
Dim objForm2 As New Form2()
End Class
-------------------------------------------
Code in Form2
-------------------------------------------
Public Class Form2
Inherits System.Windows. Forms.Form
'Windows Form Designer generated code
Dim objForm1 As New Form1()
End Class
-------------------------------------------

When I build the project (version 2002 or 2003), I get a
stack overflow.
-----Original Message-----
Bob,
Sounds like spaghetti? :-)

Can you post a sample of what you are doing? Along with

which routine you
were calling when you got the stack overflow.

Hope this helps
Jay

"Bob" <ir*****@arc.lo srios.edu> wrote in message
news:08******* *************** ******@phx.gbl. ..
Declaring a module level form object in multiple froms
within a project to show another project form causes a
stack overflow and other assorted errors. Can anyone

help?


.

Jul 21 '05 #4
Bob
Jay,

Thanks for the help! What was I trying to do?

The project involves switching between two forms from
seversl event procedures within each form. Instead of
creating the form object in each of the button click
events so that a show method could be used, I thought it
would be simpler to declare the form object as a module
level object instead of a procedure level object.

Thanks again!

Bob
-----Original Message-----
Bob,
You are using object initialization syntax. Which is causing your problems.
When you create a new Form1 a new form2 gets created, when a new form2 getscreated a new form1 gets created, which causes a new form2, which causes anew form1, which will go on until you run out of stack space.
Change these two lines:
Dim objForm1 As New Form1()
Dim objForm2 As New Form2()


To:
Dim objForm1 As Form1
Dim objForm2 As Form2


Now the problem becomes how to initialize the variables.

Normally I pass aninstance of the object to the constructor of the form (add an overloaded SubNew). Unfortunately this will not work in this case as you have two formsthat mutually refer to each other. In that case I normally have the secondobject accept the first as a parameter to the constructor, in the constuctorof the second I call a property of the first to set the reference to thesecond.

Out of curiosity: What are you attempting to do, that you have each formrefer to the other? I suspect a Singleton Pattern might be a betterapproach.

Hope this helps
Jay
"Bob" <ir*****@arc.lo srios.edu> wrote in message
news:01******* *************** ******@phx.gbl. ..
Jay,

The project has two forms with nothing on either of them.
Code in Form 1
------------------------------------------
Public Class Form1
Inherits System.Windows. Forms.Form
'Windows Form Designer generated code
Dim objForm2 As New Form2()
End Class
-------------------------------------------
Code in Form2
-------------------------------------------
Public Class Form2
Inherits System.Windows. Forms.Form
'Windows Form Designer generated code
Dim objForm1 As New Form1()
End Class
-------------------------------------------

When I build the project (version 2002 or 2003), I get a stack overflow.
>-----Original Message-----
>Bob,
>Sounds like spaghetti? :-)
>
>Can you post a sample of what you are doing? Along with
which routine you
>were calling when you got the stack overflow.
>
>Hope this helps
>Jay
>
>"Bob" <ir*****@arc.lo srios.edu> wrote in message
>news:08******* *************** ******@phx.gbl. ..
>> Declaring a module level form object in multiple
froms >> within a project to show another project form causes a >> stack overflow and other assorted errors. Can

anyone help?
>
>
>.
>

.

Jul 21 '05 #5
Bob,
that mutually refer to each other. In that case I normally have the second
object accept the first as a parameter to the

constructor, in the constuctor
of the second I call a property of the first to set the

reference to the
second. I'm not sure what happened here, it easier than this:

Seeing as the first form is creating the second form. The first form just
needs to save the reference of the second form that it created. The second
form just needs a parameter to the first on its constructor so that it can
save the reference to the first.

Something like:
Public Class Form1

Private Readonly m_form2 As Form2

Public Sub New()
m_form2 = New Form2(me)
End Sub

End Class

Public Class Form2

Private Readonly m_form1 As Form1

' needed for the designer
Private Sub New()
End Sub

Public Sub New(form1 As Form1)
MyClass.New()
m_form1 = form1
End Sub

End Class

Of course the above assumes that when one form closes the other form is soon
to close.

Hope this helps
Jay

"Bob" <ir*****@arc.lo srios.edu> wrote in message
news:05******** *************** *****@phx.gbl.. . Jay,

Thanks for the help! What was I trying to do?

The project involves switching between two forms from
seversl event procedures within each form. Instead of
creating the form object in each of the button click
events so that a show method could be used, I thought it
would be simpler to declare the form object as a module
level object instead of a procedure level object.

Thanks again!

Bob
-----Original Message-----
Bob,
You are using object initialization syntax. Which is

causing your problems.

When you create a new Form1 a new form2 gets created,

when a new form2 gets
created a new form1 gets created, which causes a new

form2, which causes a
new form1, which will go on until you run out of stack

space.

Change these two lines:
Dim objForm1 As New Form1()

Dim objForm2 As New Form2()


To:
Dim objForm1 As Form1
Dim objForm2 As Form2


Now the problem becomes how to initialize the variables.

Normally I pass an
instance of the object to the constructor of the form

(add an overloaded Sub
New). Unfortunately this will not work in this case as

you have two forms
that mutually refer to each other. In that case I

normally have the second
object accept the first as a parameter to the

constructor, in the constuctor
of the second I call a property of the first to set the

reference to the
second.

Out of curiosity: What are you attempting to do, that

you have each form
refer to the other? I suspect a Singleton Pattern might

be a better
approach.

Hope this helps
Jay
"Bob" <ir*****@arc.lo srios.edu> wrote in message
news:01******* *************** ******@phx.gbl. ..
Jay,

The project has two forms with nothing on either of

them.
Code in Form 1
------------------------------------------
Public Class Form1
Inherits System.Windows. Forms.Form
'Windows Form Designer generated code
Dim objForm2 As New Form2()
End Class
-------------------------------------------
Code in Form2
-------------------------------------------
Public Class Form2
Inherits System.Windows. Forms.Form
'Windows Form Designer generated code
Dim objForm1 As New Form1()
End Class
-------------------------------------------

When I build the project (version 2002 or 2003), I get a stack overflow.

>-----Original Message-----
>Bob,
>Sounds like spaghetti? :-)
>
>Can you post a sample of what you are doing? Along with which routine you
>were calling when you got the stack overflow.
>
>Hope this helps
>Jay
>
>"Bob" <ir*****@arc.lo srios.edu> wrote in message
>news:08******* *************** ******@phx.gbl. ..
>> Declaring a module level form object in multiple froms >> within a project to show another project form causes a >> stack overflow and other assorted errors. Can anyone help?
>
>
>.
>

.

Jul 21 '05 #6
Bob
Jay,

Thanks for all your help! It is greatly appreciated.
Jul 21 '05 #7

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

Similar topics

6
4758
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much appreciated. Thanks in advance
6
1519
by: olaf | last post by:
Hi! When using the "me." keyword (for ex. me.FilterOn = True), I sometimes (not always) get the error message: "The expression yuo entered refers to an object that is closed or doesn't exist." I really wonder why. I use it in a Form-module, to reference the form itself. The form is used as a subform in another form. Could that be the reason?
21
4427
by: Anthony England | last post by:
Everyone knows that global variables get re-set in an mdb when an un-handled error is encountered, but it seems that this also happens when the variable is defined as private at form-level. So if "global variables get re-set" doesn't tell the whole story, then what does? ***please note*** I'm not looking for a solution - I'm looking for a more detailed description of what happens when an un-handled error occurs - possibly with help file...
8
1793
by: jcrouse | last post by:
I am using the following code to trap errors in a sub routine: Try Executable code Catch ex As Exception Dim strInputE As String = Application.StartupPath & "\Error.txt" Dim srE As StreamWriter = File.AppendText(strInputE) srE.WriteLine(vbCr) srE.WriteLine(vbCr) srE.WriteLine(DateTime.Now)
6
208
by: Bob | last post by:
Declaring a module level form object in multiple froms within a project to show another project form causes a stack overflow and other assorted errors. Can anyone help?
3
2097
by: BerkshireGuy | last post by:
I have a form that contains two subforms. Both of these subforms use the same function. Rather than repeating the code, I want to be able to pass the form name to the code. Right now, its a module, but I guess it could go at the form level. I rather keep it in a module in case I ever have other forms that would use the code. The code is :
0
11599
by: Lysander | last post by:
Thought I would give something back with a few articles. This article is a bit of code to add error handling. When I have time, I want to write articles on multilingual databases, and Access Security, but I'll start with something short and simple This code was written in Access 2003 but should be valid in Access 2000 By default, when you start a new module, either in a form or report, or a global module, Access does not declare Option...
2
19495
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I will be writing this article intended for those who are in the same level, or maybe lower, of my technical knowledge. I would be using layman's words, or maybe, my own words as how I understand them, hoping, you will understand it the same way that...
0
2897
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I will be writing this article intended for those who are in the same level, or maybe lower, of my technical knowledge. I would be using layman's words, or maybe, my own words as how I understand them, hoping, you will understand it the same way that...
0
9522
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
10443
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
10216
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
9044
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
7543
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
6783
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
5565
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2921
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.