|
-
Dec 4th, 2007, 04:04 PM
#1
[RESOLVED] [2005] Get current MDI document, and error if none.
Hey,
I am using the following code to get the currently active Mdi Child (document) in my program. It works perfectly.
Code:
Public Function GetDoc() As frmDocument
Dim doc As frmDocument = CType(Me.ActiveMdiChild, frmDocument)
Return doc
End Function
However, when I try to use the result from "GetDoc()" if there are NO Mdi childs open at the time of calling "GetDoc()", then it errors.
How can I tell if there are no mdi childs open, so I can inform the user he/she is trying to do something impossible, without the program crashing?
I have tried this, but it didn't work: (Error: Object reference not set to an instance of an object.)
Code:
Public Function GetDoc() As frmDocument
Dim doc As frmDocument = CType(Me.ActiveMdiChild, frmDocument)
If Me.ActiveMdiChild.Name = "" Then
MessageBox.Show("Open a script first please!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Return Nothing
Else
Return doc
End If
End Function
I know I could just make it give this message on every error that happens, but I don't want to do that if I don't have to... I can imagine a few other erros occuring, and I want to be able to give the user as much feedback as possible, instead of giving the same "Some unknown error happened" message at each error...
Thanks!
Last edited by NickThissen; Dec 4th, 2007 at 04:08 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|