Declaration of variables for forms

R

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.
 
R

Richie Glenn

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top