Stumped

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
Try checking to see if Me.MdiChildren is Nothing before the loop. The
length statement might break it?

That's just a guess
 
Benny:

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

The same behavior still exists!
 
Try adding a breakpoint right before you call your End...

Which.. you *really* shouldn't call End...
 
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
 
Hi,

Try this code instead:
Dim child As Form

For Each child In Me.MdiChildren

child.Close()

Next

Application.Exit

HTH,

Bernie Yaeger
 
Back
Top