|
-
Apr 30th, 2006, 05:48 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Using exit method...
VB Code:
if condition then
...
end if
VB Code:
if not condition then
exit sub
end if
...
Which of these 2 should we generally use? I don't know if it's just a matter of taste of using exit or not, but I like using it, although the code looks kind of messy if someone else reads it. Is there anything wrong about this?
-
Apr 30th, 2006, 05:52 PM
#2
Frenzied Member
Re: Using exit method...
I hardly use "Exit Sub" in my coding. Usually only when I have large structured subs that require to exit multiple times. Generally if my program is going to have a single if statement I go like:
VB Code:
Private Sub Test()
If condition Then
...
End If
End Sub
Then if the condition is false nothing would have happened in the first place.
Age - 15 ::: Level - Advanced
If you find my post useful please ::Rate It::

-
Apr 30th, 2006, 05:58 PM
#3
Thread Starter
Addicted Member
Re: Using exit method...
Yes, but I don't like to have in my code too many imbricated if's, but I agree that too many exit's look confusing when someone else read the code. In my case noone will read the code I write now, but I will be a programmer soon, so I'd like to know how things should be done... 
Thank you.
-
Apr 30th, 2006, 06:20 PM
#4
Re: Using exit method...
First off, typing Return is probably faster than typing exit sub.
Some people STRONGLY dislike having more than one exit point for a sub or function, but I am not in that camp. I think testing for a condition at the beginning of a sub and bailing out if the condition is not met is entirely understandable. If people would have a difficult time with what amounts to an assertion, then comment the heck out of it.
My usual boring signature: Nothing
 
-
Apr 30th, 2006, 06:29 PM
#5
Thread Starter
Addicted Member
Re: Using exit method...
 Originally Posted by Shaggy Hiker
First off, typing Return is probably faster than typing exit sub.
You do have a point
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
|