|
-
Oct 16th, 2008, 01:06 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Will Me.Close execute twice?
I'm cleaning up the code in some projects, doing things like moving Me.Close to Finally when both the Try & Catch end by closing the form.
Theoretically, this project should probably run from a Sub Main but it's built with a user login form as the startup form-so everything runs from that form & when it closes the application ends. I'll try to summarize the code:
Code:
Try
If Invalid_Password Then
Me.Close
End If
Me.Hide
NextForm.ShowDialog
Catch
Show_Error
Finally
Me.Close
End Try
Now, my question is if the password is invalid will it try to close the form twice & if so will it cause a problem? If not then what would be the best way to handle this? (Other than eliminating the Finally block & ending both Try & Catch with Me.Close)
I could, I suppose, put Me.Hide & ShowDialog in an Else clause but there's considerable code in between that I left out in the summary. I don't know about you, but personally I hate IF/Else blocks with more than 5-10 lines of code.
Thanks.
-
Oct 16th, 2008, 01:22 PM
#2
Re: Will Me.Close execute twice?
Yes, the call would be made twice. I would do this:
Code:
Try
If Not Invalid_Password Then
Me.Hide
NextForm.ShowDialog
End If
Catch
Show_Error
Finally
Me.Close
End Try
-
Oct 16th, 2008, 01:27 PM
#3
Thread Starter
Hyperactive Member
Re: Will Me.Close execute twice?
As I mentioned, the two lines in the summary are 'shorthand' for a considerable body of code. I'd really prefer to find a clean way of ending the program in the If block. Or, I can go back to the original form:
Code:
Try
If Invalid_Password Then
Me.Close
End If
Me.Hide
NextForm.ShowDialog
Me.Close
Catch
Show_Error
Me.Close
End Try
It looks wrong (like it should use a Finally block) but I could always add a comment explaining why it doesn't.
Thanks.
Last edited by calvin-c; Oct 16th, 2008 at 01:31 PM.
-
Oct 16th, 2008, 01:38 PM
#4
Re: Will Me.Close execute twice?
Code:
Try
If Invalid_Password Then
Exit Try
End If
Me.Hide
NextForm.ShowDialog
Catch
Show_Error
End Try
'what code is here?
'if it is end sub then won't you get .Close here?
-
Oct 16th, 2008, 01:55 PM
#5
Thread Starter
Hyperactive Member
Re: Will Me.Close execute twice?
Thank you. I think Exit Try is what I was looking for. IIRC the Finally block always executes, even following Exit Try, which is what I want.
Yes, I could put .Close following End Try but I don't like having code outside Try/Catch blocks-no error checking.
-
Oct 16th, 2008, 02:31 PM
#6
Re: [RESOLVED] Will Me.Close execute twice?
I was asking what was after the end try statement?
-
Oct 16th, 2008, 05:42 PM
#7
Thread Starter
Hyperactive Member
Re: [RESOLVED] Will Me.Close execute twice?
End Sub-but I don't see why that's relevant. You seem to suggest that End Sub will automatically close the form-but it doesn't. It would if this were a Sub Main, but it isn't. It's a startup form so End Sub simply returns to displaying the form.
-
Oct 16th, 2008, 05:53 PM
#8
Re: [RESOLVED] Will Me.Close execute twice?
i thought it was the other way around
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
|