Stumped

G

Guest

Hello:

I have an MDI application. When the user selects File/Exit, the following
code executes:

Do While Me.MdiChildren.Length > 0
Me.MdiChildren(0).Close()
Loop
End

This code executes fine. Until I click on Help/About that opens a dialog
box. When I close the About dialox box and then click on File/Exit, I get the
exception:

An unhandled exception of type 'System.NullReferenceException' occurred in
Unknown Module.

Additional information: Object reference not set to an instance of an object.

When I break, it says "There is no source code available for the current
location.

There's no MDI child window open.

Can somebody enlighten me on this?

Venkat
 
B

Benny Raymond

Try checking to see if Me.MdiChildren is Nothing before the loop. The
length statement might break it?

That's just a guess
 
G

Guest

Benny:

I removed all the code. Now the clicked event has only "End".

The same behavior still exists!
 
C

CJ Taylor

Try adding a breakpoint right before you call your End...

Which.. you *really* shouldn't call End...
 
G

Guest

CJ:

I changed the clicked event to:
Try
End
Catch ex As Exception
MsgBox(ex.Message)
End Try

But even this does not catch the exception. Strangely, there is another
modal window that I open and the application exits fine!

Venki
 
B

Bernie Yaeger

Hi,

Try this code instead:
Dim child As Form

For Each child In Me.MdiChildren

child.Close()

Next

Application.Exit

HTH,

Bernie Yaeger
 

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