|
-
Jul 14th, 2000, 10:41 PM
#1
Thread Starter
Addicted Member
I have a structural question... I'm guessing that it'll come down to a matter of tastes, but...
Is it better (looking, working, compiling, etc...) to do an exit sub, or to allow the sub to finish normaly by the use of if statements?
i.e. -
Code:
'Hard or Forced Method
Public Sub example()
If (conditions are not right) then exit sub
'Do subroutine code...
End sub
or
Code:
'Soft Method
Public Sub example()
If (conditions are right) then
'Do subroutine code...
End If
End sub
What do you guys think?
Any efficiency concerns with something like this?
-
Jul 14th, 2000, 10:46 PM
#2
Fanatic Member
I usually prefer to use Exit Sub. Just a personal preference I guess.
-
Jul 14th, 2000, 10:50 PM
#3
Frenzied Member
I'd Say Exit Sub, Especcially if you had lots of them, If you're going to do that then somewhere you'll have a chouce between 3 exit subs or 3 nested ifs, also an exit sub can be inside a liip or if statement, You can't do that with an If Statement
-
Jul 14th, 2000, 11:01 PM
#4
I'd say use the Soft Method or something like:
Code:
Public Sub example()
If (conditions are right) then
'Do subroutine code...
Else
Exit Sub
End If
End Sub
But..if you have more than one code or something..than go with Sam's idea.
[Edited by Matthew Gates on 07-15-2000 at 12:03 AM]
-
Jul 15th, 2000, 07:09 AM
#5
I prefer to use the Select Case statement when possible, it looks better.
Code:
Dim Variable As String
Select Case Variable
Case "String"
MsgBox "String"
Case "Form2"
Form2.Show
Case "Exit Sub"
Exit Sub
Case "End"
Dim F As Form
For Each F In Forms
Unload F
Next F
End Select
-
Jul 15th, 2000, 07:15 AM
#6
There is no difference in the code implementation when vb hits the bottom of that sub routine it hits end sub which is the exact equivalant of exit sub. When the If then statement is ran the code is very flexible afterwards for the easability to add more code to it. If you use the exit sub routine you can not add extra parameters as easily. Also coding structure is good to follow. I try to avoid skipping around in my code and let it be ran from top to bottom(how its suppose to be).
This is a personal opinion though
-
Jul 15th, 2000, 10:20 AM
#7
Either is fine with me. They are basically doing the same thing. The Forced method exits the Sub at the beginning and the soft method exits the Sub at the end. Neither is more flexible then the other, the only difference is that they are inverted.
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
|