By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,534 Members | 910 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,534 IT Pros & Developers. It's quick & easy.

Strange Problem

P: n/a
im running the code below when a new item is selected within a combobox the
code runs fine but when it gets to me.close it crashes - it doesnt start the
next form just crashes (its not debugabble) it seems to be a problem with
the .net framwork - have i done something silly, or have i found a known
bug - if so is there a workaround?

Thanks in advance for your help

Mike Fellows

Private Sub ComboBox3_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ComboBox3.SelectedIndexChanged
If Loading = False Then
TimeAddy = Me.ComboBox3.Text.ToString
SaveFactFind()

If Me.ComboBox3.Text = "36 Months or over" Then
Dim x As New TotalTimeAtAddress
x.ID = ID
x.show()
Else
Dim x As New PreviousAddresses
x.ID = ID
x.Show()
End If
Me.Close()
End If
End Sub
Nov 21 '05 #1
Share this Question
Share on Google+
15 Replies


P: n/a
How was the program started?

If you use
Application.Run(new MyForm)
, then the application will exit when the aforementioned form is closed.

If you use
Dim X as new MyForm
x.Show
Application.Run
, then the application will exit when all forms are closed.

--
Jonathan Allen
"Mike Fellows" <mi*************@equityhouse.NOSPAM.co.uk> wrote in message
news:4p********************@giganews.com...
im running the code below when a new item is selected within a combobox
the
code runs fine but when it gets to me.close it crashes - it doesnt start
the
next form just crashes (its not debugabble) it seems to be a problem with
the .net framwork - have i done something silly, or have i found a known
bug - if so is there a workaround?

Thanks in advance for your help

Mike Fellows

Private Sub ComboBox3_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ComboBox3.SelectedIndexChanged
If Loading = False Then
TimeAddy = Me.ComboBox3.Text.ToString
SaveFactFind()

If Me.ComboBox3.Text = "36 Months or over" Then
Dim x As New TotalTimeAtAddress
x.ID = ID
x.show()
Else
Dim x As New PreviousAddresses
x.ID = ID
x.Show()
End If
Me.Close()
End If
End Sub

Nov 21 '05 #2

P: n/a
"Jonathan Allen" <x@x.x> schrieb
How was the program started?

If you use
Application.Run(new MyForm)
, then the application will exit when the aforementioned form is
closed.
If you use
Dim X as new MyForm
x.Show
Application.Run
, then the application will exit when all forms are closed.

No, it does not exit. You would have to call application.exitthread to exit
Application.Run.

Armin

Nov 21 '05 #3

P: n/a

"Armin Zingler" <az*******@freenet.de> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
"Jonathan Allen" <x@x.x> schrieb
How was the program started?

If you use
Application.Run(new MyForm)
, then the application will exit when the aforementioned form is
closed.
If you use
Dim X as new MyForm
x.Show
Application.Run
, then the application will exit when all forms are closed.

No, it does not exit. You would have to call application.exitthread to
exit Application.Run.

Armin


Yes, it does exit. The Application.Run(Form) overload adds an event handler
to the Closed event for the Form. When the Closed event it raised, the
event handler calls ExitThread to clean up the application.

MSDN Library Link:
ms-help://MS.MSDNQTR.2003FEB.1033/cpref/html/frlrfsystemwindowsformsapplicationclassruntopic3.h tm

This is explained in the above link :)

HTH,
Mythran

Nov 21 '05 #4

P: n/a
"Mythran" <ki********@hotmail.comREMOVETRAIL> schrieb

"Armin Zingler" <az*******@freenet.de> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
"Jonathan Allen" <x@x.x> schrieb
How was the program started?

If you use
Application.Run(new MyForm)
, then the application will exit when the aforementioned form is
closed.
If you use
Dim X as new MyForm
x.Show
Application.Run
, then the application will exit when all forms are closed.

No, it does not exit. You would have to call application.exitthread
to exit Application.Run.

Armin


Yes, it does exit. The Application.Run(Form) overload adds an event
handler to the Closed event for the Form. When the Closed event it
raised, the event handler calls ExitThread to clean up the
application.
MSDN Library Link:
ms-help://MS.MSDNQTR.2003FEB.1033/cpref/html/frlrfsystemwindowsformsapplicationclassruntopic3.h tm

This is explained in the above link :)

I was referring to the last statement I quoted. Application.run without
arguments does not exit when all forms are closed.

Armin

Nov 21 '05 #5

P: n/a
I was referring to the last statement I quoted. Application.run without
arguments does not exit when all forms are closed.

Armin


Ahh, my apologies, I got ahead of myself :)

Mythran

Nov 21 '05 #6

P: n/a
im using:

Dim x As New TotalTimeAtAddress
x.ID = ID
x.show()
me.close()
the problem is the code crashes out (not exits, crashes) before the new form
is even displayed

i understand that if all forms where closed then the program would exit -
but that isnt the case - it crashes out (but not when in debug mode)


"Jonathan Allen" <x@x.x> wrote in message
news:O7**************@TK2MSFTNGP15.phx.gbl...
How was the program started?

If you use
Application.Run(new MyForm)
, then the application will exit when the aforementioned form is closed.

If you use
Dim X as new MyForm
x.Show
Application.Run
, then the application will exit when all forms are closed.

--
Jonathan Allen
"Mike Fellows" <mi*************@equityhouse.NOSPAM.co.uk> wrote in message
news:4p********************@giganews.com...
im running the code below when a new item is selected within a combobox
the
code runs fine but when it gets to me.close it crashes - it doesnt start
the
next form just crashes (its not debugabble) it seems to be a problem with the .net framwork - have i done something silly, or have i found a known
bug - if so is there a workaround?

Thanks in advance for your help

Mike Fellows

Private Sub ComboBox3_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox3.SelectedIndexChanged
If Loading = False Then
TimeAddy = Me.ComboBox3.Text.ToString
SaveFactFind()

If Me.ComboBox3.Text = "36 Months or over" Then
Dim x As New TotalTimeAtAddress
x.ID = ID
x.show()
Else
Dim x As New PreviousAddresses
x.ID = ID
x.Show()
End If
Me.Close()
End If
End Sub


Nov 21 '05 #7

P: n/a
"Mike Fellows" <mi*************@equityhouse.NOSPAM.co.uk> schrieb
im using:

Dim x As New TotalTimeAtAddress
x.ID = ID
x.show()
me.close()
the problem is the code crashes out (not exits, crashes) before the
new form is even displayed

i understand that if all forms where closed then the program would
exit - but that isnt the case - it crashes out (but not when in debug
mode)


What does "crash" mean? Do you hear anything? ;-) Do you see a message? What
does it say?

Armin

Nov 21 '05 #8

P: n/a
ok i have worked out my problem, i just dont know how to fix it

on loading my form i do a loas of stuff to comboboxes (set values etc..)
while the form is loading i have a variable called loading that i set to
true.

so when i change a value of combobox and run some code i check that loading
= false
so that when setting values of comboboxes on form load it doesnt run this
code

looks somehting like this:

Private Sub ComboBox3_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ComboBox3.SelectedIndexChanged
If Loading = False Then

do_stuff_here()

End If
End Sub

now if i add a me.close into the if loading = false statement so it looks
like this

If Loading = False Then

do_stuff_here()

me.close()
End If
when it eventully runs it does the do_stuff_here function then closes the
form
but then in debug mode it carries on after the me.close to the endif
statement
and crashes which has obvioulsy gone due to the me.close and crashes with
object reference not set to an instance of an object

i cant think of a solution to this and have no idea what to try, any help
would
be appreciated as im completely stuck now

"Mike Fellows" <mi*************@equityhouse.NOSPAM.co.uk> wrote in message
news:QN********************@giganews.com...
im using:

Dim x As New TotalTimeAtAddress
x.ID = ID
x.show()
me.close()
the problem is the code crashes out (not exits, crashes) before the new form is even displayed

i understand that if all forms where closed then the program would exit -
but that isnt the case - it crashes out (but not when in debug mode)


"Jonathan Allen" <x@x.x> wrote in message
news:O7**************@TK2MSFTNGP15.phx.gbl...
How was the program started?

If you use
Application.Run(new MyForm)
, then the application will exit when the aforementioned form is closed.

If you use
Dim X as new MyForm
x.Show
Application.Run
, then the application will exit when all forms are closed.

--
Jonathan Allen
"Mike Fellows" <mi*************@equityhouse.NOSPAM.co.uk> wrote in message
news:4p********************@giganews.com...
im running the code below when a new item is selected within a combobox the
code runs fine but when it gets to me.close it crashes - it doesnt start the
next form just crashes (its not debugabble) it seems to be a problem

with the .net framwork - have i done something silly, or have i found a known bug - if so is there a workaround?

Thanks in advance for your help

Mike Fellows

Private Sub ComboBox3_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox3.SelectedIndexChanged
If Loading = False Then
TimeAddy = Me.ComboBox3.Text.ToString
SaveFactFind()

If Me.ComboBox3.Text = "36 Months or over" Then
Dim x As New TotalTimeAtAddress
x.ID = ID
x.show()
Else
Dim x As New PreviousAddresses
x.ID = ID
x.Show()
End If
Me.Close()
End If
End Sub



Nov 21 '05 #9

P: n/a
Mike,

Everybody is asking the same to you.

I try it in my words. What is *me* it is obviously a form I can see from
your answers. However, how did you start this form.

In other words:
Is it a mainform that starts automaticly conform VBNet rules.
Did you creade an extra module to start that mainform
Is it maybe a form instanced in the mainform where the mainform is no owner.

etc etc.

Cor
Nov 21 '05 #10

P: n/a
apologies

me is justa windows form called from the main form it is started like:

dim x as new myform
myform.show

me = myform

thanks

"Cor Ligthert" <no************@planet.nl> wrote in message
news:uo**************@TK2MSFTNGP09.phx.gbl...
Mike,

Everybody is asking the same to you.

I try it in my words. What is *me* it is obviously a form I can see from
your answers. However, how did you start this form.

In other words:
Is it a mainform that starts automaticly conform VBNet rules.
Did you creade an extra module to start that mainform
Is it maybe a form instanced in the mainform where the mainform is no owner.
etc etc.

Cor

Nov 21 '05 #11

P: n/a
Mike,

Another questions,

What is the sense of this
If Loading = False Then

do_stuff_here()

me.close()
End If

You probably start another form in that do_stuff_here.

With me.close you try to delete all references that you have in your
program.
(To your mainform where it is instanced and to your subform that you
instanced)

My expection is that this kind of program should crash or give unpredictable
results which can be the reason that it crashes in the debugger..

However maybe have others better ideas. This is just a guess.

Cor
Nov 21 '05 #12

P: n/a
ok

how would you recommend that i open a new form that no longer requires the
current form

i need to populate a public variable within this form when it loads

to be honest i have always written the above like this

dim x as new mynewform()
x.publicvariable = variable
x.show
me.close()

never had any problems with the above until now

am i doing this wrong? im self taught in vb.net as i moved from c++ so i
have no idea if what i am doing is corrent

thanks

Mike
"Cor Ligthert" <no************@planet.nl> wrote in message
news:OM**************@tk2msftngp13.phx.gbl...
Mike,

Another questions,

What is the sense of this
If Loading = False Then

do_stuff_here()

me.close()
End If

You probably start another form in that do_stuff_here.

With me.close you try to delete all references that you have in your
program.
(To your mainform where it is instanced and to your subform that you
instanced)

My expection is that this kind of program should crash or give unpredictable results which can be the reason that it crashes in the debugger..

However maybe have others better ideas. This is just a guess.

Cor

Nov 21 '05 #13

P: n/a
Mike,

I tried it in a test like this. The result was be in my test that the form x
will be showed. (Not actualy because before it is painted it is already
removed because that in my test the parent was closed)

\\\
Label1.Text = x.ToString
If x < 10 Then
Dim frm As New Form12
frm.x = x + 1
frm.Show()
If x > 5 Then
Me.Close()
End If
End If
///

I would do your problem with events, and close the forms from the place I
have instanced them. However, that is my approach.

Cor

Nov 21 '05 #14

P: n/a
Thanks Cor

i sort of understand what your saying

but the way im doing it now is the way i have always done it, and i have
never ever had a problem before

all very strange

thanks though
"Cor Ligthert" <no************@planet.nl> wrote in message
news:OC**************@TK2MSFTNGP09.phx.gbl...
Mike,

I tried it in a test like this. The result was be in my test that the form x will be showed. (Not actualy because before it is painted it is already
removed because that in my test the parent was closed)

\\\
Label1.Text = x.ToString
If x < 10 Then
Dim frm As New Form12
frm.x = x + 1
frm.Show()
If x > 5 Then
Me.Close()
End If
End If
///

I would do your problem with events, and close the forms from the place I
have instanced them. However, that is my approach.

Cor

Nov 21 '05 #15

P: n/a
You mention that it crashes. Is there an error? If so what is it and
can you print out the stack trace?

Nov 21 '05 #16

This discussion thread is closed

Replies have been disabled for this discussion.