ayozzhero
Well-known member
I learned that using EXIT statement is best to be avoided. However, I do not see the way how it should be implemented without putting so many codes to replace the EXIT statement.
Given a very simple example for a save button procedure:
From what I see, the easiest way is to put Exit Sub for do nothing. This way, the execution stops straight away because no further process is necessary. If I want to avoid the Exit Sub, I would have to put a boolean/variable as replacement, and do some more codes to handle the logic.
In such a simple procedure like this, it might not be a big hassle to create a True/False condition (boolean), but imagine a procedure that has so many logics. However, putting Exit Sub in in so many places raises cost in other ways. It is hard to trace the culprit of an error since 'one entry has many doors to exit'.
How do I balance between them, or what practice should I take actually. Any opinion is most welcomed.
Thank you.
Given a very simple example for a save button procedure:
VB.NET:
if user types nothing
notify user that nothing is changed
do nothing
end if
if what user types is the same as the existing one
notify user that nothing is changed
do nothing
end if
if user types restricted words
notify user
do nothing
end if
apart from that
ask user for confirmation
if user clicks ok
save the form
reset form
notify user
else
do nothing
end if
From what I see, the easiest way is to put Exit Sub for do nothing. This way, the execution stops straight away because no further process is necessary. If I want to avoid the Exit Sub, I would have to put a boolean/variable as replacement, and do some more codes to handle the logic.
In such a simple procedure like this, it might not be a big hassle to create a True/False condition (boolean), but imagine a procedure that has so many logics. However, putting Exit Sub in in so many places raises cost in other ways. It is hard to trace the culprit of an error since 'one entry has many doors to exit'.
How do I balance between them, or what practice should I take actually. Any opinion is most welcomed.
Thank you.