473,395 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Stop function

Hello,

On the start of a function I need to verify a condition.

If it is false I want the rest of the code to not run.

My question is:

should I put all the function code inside an IF or is there a command
that I should use that interrupts the function?

My function is as follows:

Private Sub MyF()

End Sub

Thanks,

Miguel

Mar 10 '07 #1
2 1592
the following pseudo code is pretty safe:

private bool MyF()
{
bool result = false;
try
{
if ( Condition )
{
// do this
result = true;
}
else
{
// write to log that condition was false
}
}
catch ( Exception ex)
{
}
return result;
}

"shapper" <md*****@gmail.comwrote in message
news:11**********************@v33g2000cwv.googlegr oups.com...
Hello,

On the start of a function I need to verify a condition.

If it is false I want the rest of the code to not run.

My question is:

should I put all the function code inside an IF or is there a command
that I should use that interrupts the function?

My function is as follows:

Private Sub MyF()

End Sub

Thanks,

Miguel

Mar 10 '07 #2
shapper wrote:
Hello,

On the start of a function I need to verify a condition.

If it is false I want the rest of the code to not run.

My question is:

should I put all the function code inside an IF or is there a command
that I should use that interrupts the function?

My function is as follows:

Private Sub MyF()

End Sub

Thanks,

Miguel
What you use is mostly a matter of taste and conviction.

Some say that a method should only have one exit point. The reason is
that it's easier to follow the flow in the method if you know that it
always ends in the same way.

If you follow this advice is up to you, and how complex your method is.
A method that is only a few lines isn't that hard to follow even if it
has more than one exit point. On the other hand, if it's not hard to
accomplish, you can just as well follow the advice.

To exit from a Sub, use the Exit Sub command. Example:

Sub ASmallDemoSub(input as String)
If String.IsNullOrEmpty(input) Then
Exit Sub
End If
'... do something
End Sub

It might be just as easy to keep the single exit point:

Sub ASmallDemoSub(input as String)
If Not String.IsNullOrEmpty(input) Then
'... do something
End If
End Sub

--
Göran Andersson
_____
http://www.guffa.com
Mar 11 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: engsol | last post by:
I'm using Python to parse a bunch of s/w test files and make csv files for later report generation by MS ACCESS....(my boss loves the quick turn-around compared to C). Each log file may contain one...
8
by: Eric Osman | last post by:
My javascript program has reason to want to stop. For example, function A has 5 lines, the second of which calls function B, which has 5 lines, the first of which calls function C. But...
2
by: Adrian MacNair | last post by:
Hi I need some help if anyone can understand my crap javascript. The problem is that after the slideshow ends (reaches the end of array) it should stop, but the timeout doesn't clear and I can see...
4
by: ravindarjobs | last post by:
hi...... i am using ms access 2003,vb6 i have a form. in that i have 2 buttons 1. start search 2 stop search when i click the "start search" button the fucntion SearchSystem() is called,...
8
praclarush
by: praclarush | last post by:
Ok, I'm new to JavaScript and I'm taking a class for it the assignment in it I'm supposed to create edit a pre-made page to display a marquee that automatically scrolls for the user, as well as give...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.