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

Declaration of variables for forms

Rob
I am doing something wrong in declaring variables for
forms I want to load. When the declaration is read, the
form closes. I have a form, Form1, that loads at
startup. After the Windows-generated code for Form1,
there are a few declarations: Public Shared frm2 As New
Form2, Public Shared frm3 As New Form3, etc., for five
different forms called from Form1. I've just added a new
form to the application, Form6, and declared it
as "Public Shared frm6 As New Form6" As soon as this
line of code is read, the main startup form closes,
causing the application itself to close. I've
experienced this problem elsewhere in my code, where a
form will close unexpectedly, obviously due to the way
I'm declaring the form variables. What can I do to fix
this? I have already tried declaring the variables
inside the subroutines where the forms are called up, and
I've tried declaring them in various ways, i.e., Dim
Withevents, Public Shared Withevents, etc.
Nov 20 '05 #1
3 1383
Rob

If I understand you, you have

Class Form1
Dim Shared frm2 As New Form2
Dim Shared frm3 As New Form3
Dim Shared frm4 As New Form4
Dim Shared frm5 As New Form5
Dim Shared frm6 As New Form6

and it dies on the last one.

This is either due to there being 5 of them (unlikely) or it's due to Form6.

Replace
Dim Shared frm6 As New Form6
with
Dim Shared anotherfrm5 As New Form5
and see if it still happens.

If so, there is a problem. If not, then Form6 is doing something wrong in
its constructor (Sub New)

Richie
Nov 20 '05 #2
Rob
Richie

Thanks for your help. I tried declaring another variable
for a different form and it worked fine. I've examined
Form6's constructor and can't see that it looks any
different than any other form's constructor. I don't
know how anything could go wrong with the constructor
anyway, since VS does the constructing. Here is the
first part of it if you can take a look at it:

Public Class frmSPARKBar
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows
Form Designer.
InitializeComponent()

'Add any initialization after the
InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component
list.
Protected Overloads Overrides Sub Dispose(ByVal
disposing As Boolean)
If disposing Then
If Not (components Is Nothing)
Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Nov 20 '05 #3
Hi Don,

There's nothing obviously wrong. Does frmSPARKBar use DC or AC?

Seriously though, I guess there are some more things tio try.

One is to see if having New Form6 as the <first> makes it die. That can
indicate or eliminate a cumulative effect. And that makes me think of a
question - how do you know that it dies then? If it's because there's an error
message....?

Another test: If it's definitely dying in New Form6 then it has to be
something in InitializeComponent. If you avoid changing the Form when in the
Designer, you can add code to InitializeComponent without it being wiped out
by the autogenerator. You can thus add loads of debugs/MsgBoxes to narrow the
gap down.

Finally, you could post some more info here. If you're totally stumped, it
might be best to post the project in a zip (without the obj or bin
directories). See if you can eliminate Forms 2 to 5 as well while still
retaining the problem.

Good luck.

Regards,
Fergus
Nov 20 '05 #4

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

Similar topics

83
by: Alexander Zatvornitskiy | last post by:
Hello All! I'am novice in python, and I find one very bad thing (from my point of view) in language. There is no keyword or syntax to declare variable, like 'var' in Pascal, or special syntax in...
13
by: genetic.error | last post by:
I'm moving from Vb6 to VB.Net. I have a feeling this has come up before... The VS.Net MSDN file seems to state that the following should work: Form1.Show Form1.Visible = True Form1.Hide...
17
by: MLH | last post by:
A97 Topic: If there is a way to preserve the values assigned to global variables when an untrapped runtime error occurs? I don't think there is, but I thought I'd ask. During development, I'm...
15
by: CR | last post by:
I've noticed that the trend these days is to declare variables in the middle of code instead of at the top. What is the advantage of this? It seems like it makes it hard to reuse variables. Here...
6
by: jcrouse | last post by:
I have a project with a startup (Sub Main) module and two forms. Based on the logic in the Sub Main it calls one of the two forms. The two forms are almost identical. They both make calls into the...
9
by: Marcel Saucier | last post by:
Hello everybody, I want to declare an array in form1, load it in form1 and then access that array in form2. New in VB, It took me a while to understand that declaring variables right under class...
28
by: Larax | last post by:
Best explanation of my question will be an example, look below at this simple function: function SetEventHandler(element) { // some operations on element element.onclick = function(event) {
9
by: Jess | last post by:
Hello, I was told that if I declare a static class constant like this: class A{ static const int x = 10; }; then the above statement is a declaration rather than a definition. As I've...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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:
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
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.