473,696 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Return vs Exit Sub

Is there any difference between Return and Exit Sub?

I have some code that uses both when I have an error in my Sub.

Thanks,

Tom
Jul 21 '06 #1
14 20962
Hello tshad,

There is no difference in the IL output from "Return" and "Exit Sub" when
used in a sub. However, for readability I would suggtest using Exit Sub.
Return denotes pushing a value back to the caller, which since a sub doesnt
have a return value, makes for a less clear intent.

-Boo
Is there any difference between Return and Exit Sub?

I have some code that uses both when I have an error in my Sub.

Thanks,

Tom

Jul 21 '06 #2
Tshad,

There should be not any difference although I prefer Exit Sub.

Cor

"tshad" <ts**********@f tsolutions.coms chreef in bericht
news:uR******** ******@TK2MSFTN GP05.phx.gbl...
Is there any difference between Return and Exit Sub?

I have some code that uses both when I have an error in my Sub.

Thanks,

Tom

Jul 21 '06 #3
"GhostInAK" <gh*******@gmai l.comschrieb:
>There is no difference in the IL output from "Return" and "Exit Sub" when
used in a sub. However, for readability I would suggtest using Exit Sub.
Return denotes pushing a value back to the caller, which since a sub doesnt
have a return value, makes for a less clear intent.
Well, you could interpret 'Return' either as "Return something" or "Return
to something".

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jul 21 '06 #4
Herfried,
Well, you could interpret 'Return' either as "Return something" or "Return
to something".
It is not about holidays.

It is about a nothing returning method in VBNet what has the name Sub.

In far past when stacks did not yet be used, there was set a return address
mostly as last command in a method.

I never investigated this but in a normal modern system, the sub ends and
the program goes on in the one higher stack; one position after where it was
calling the Sub.

:-)

Cor

"Herfried K. Wagner [MVP]" <hi************ ***@gmx.atschre ef in bericht
news:eF******** ******@TK2MSFTN GP02.phx.gbl...
"GhostInAK" <gh*******@gmai l.comschrieb:
>>There is no difference in the IL output from "Return" and "Exit Sub" when
used in a sub. However, for readability I would suggtest using Exit Sub.
Return denotes pushing a value back to the caller, which since a sub
doesnt have a return value, makes for a less clear intent.

Well, you could interpret 'Return' either as "Return something" or "Return
to something".

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jul 21 '06 #5

"Cor Ligthert [MVP]" <no************ @planet.nlwrote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
Herfried,
Well, you could interpret 'Return' either as "Return something" or
"Return
to something".
It is not about holidays.

It is about a nothing returning method in VBNet what has the name Sub.

In far past when stacks did not yet be used, there was set a return
address
mostly as last command in a method.

I never investigated this but in a normal modern system, the sub ends and
the program goes on in the one higher stack; one position after where it
was
calling the Sub.
There is an implicit return at the end of a Sub. As far as using Exit Sub
or Return, I have switched to Return as most other languages use Return for
this purpose. VB was the only language to not use return in this manner
because the BASIC return statement indicated the return from a GOSUB
statement.

Mike.
>
:-)

Cor

"Herfried K. Wagner [MVP]" <hi************ ***@gmx.atschre ef in bericht
news:eF******** ******@TK2MSFTN GP02.phx.gbl...
"GhostInAK" <gh*******@gmai l.comschrieb:
>There is no difference in the IL output from "Return" and "Exit Sub"
when
>used in a sub. However, for readability I would suggtest using Exit
Sub.
>Return denotes pushing a value back to the caller, which since a sub
doesnt have a return value, makes for a less clear intent.
Well, you could interpret 'Return' either as "Return something" or
"Return
to something".

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>




Jul 21 '06 #6
Boo,
I view Return as returning to whence I came. Which as Michael suggests is
common across most other languages.

Optionally a value may be included when I return to whence I came.

Unfortunately I am inconsistent on always using Return; I occasionally use
Exit Sub... Which could be considered an odd-ball solution...

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"GhostInAK" <gh*******@gmai l.comwrote in message
news:c7******** *************** ***@news.micros oft.com...
| Hello tshad,
|
| There is no difference in the IL output from "Return" and "Exit Sub" when
| used in a sub. However, for readability I would suggtest using Exit Sub.
| Return denotes pushing a value back to the caller, which since a sub
doesnt
| have a return value, makes for a less clear intent.
|
| -Boo
|
| Is there any difference between Return and Exit Sub?
| >
| I have some code that uses both when I have an error in my Sub.
| >
| Thanks,
| >
| Tom
| >
|
|
Jul 21 '06 #7
Michael,

VBNet is the only language where I am/was easily able to go deeper than 8
levels. That because of the nice descriptions of the levels.

:-)

Cor

"Michael D. Ober" <obermd.@.alum. mit.edu.nospams chreef in bericht
news:V6******** ********@newsre ad3.news.pas.ea rthlink.net...
>
"Cor Ligthert [MVP]" <no************ @planet.nlwrote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
>Herfried,
Well, you could interpret 'Return' either as "Return something" or
"Return
to something".
It is not about holidays.

It is about a nothing returning method in VBNet what has the name Sub.

In far past when stacks did not yet be used, there was set a return
address
>mostly as last command in a method.

I never investigated this but in a normal modern system, the sub ends and
the program goes on in the one higher stack; one position after where it
was
>calling the Sub.

There is an implicit return at the end of a Sub. As far as using Exit Sub
or Return, I have switched to Return as most other languages use Return
for
this purpose. VB was the only language to not use return in this manner
because the BASIC return statement indicated the return from a GOSUB
statement.

Mike.
>>
:-)

Cor

"Herfried K. Wagner [MVP]" <hi************ ***@gmx.atschre ef in bericht
news:eF******* *******@TK2MSFT NGP02.phx.gbl.. .
"GhostInAK" <gh*******@gmai l.comschrieb:
There is no difference in the IL output from "Return" and "Exit Sub"
when
>>used in a sub. However, for readability I would suggtest using Exit
Sub.
>>Return denotes pushing a value back to the caller, which since a sub
doesnt have a return value, makes for a less clear intent.

Well, you could interpret 'Return' either as "Return something" or
"Return
to something".

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>





Jul 21 '06 #8
Jay,

Have a look at my reply to Michael, otherwise I would agree with you.

:-)

Cor

"Jay B. Harlow [MVP - Outlook]" <Ja************ @tsbradley.nets chreef in
bericht news:uX******** ******@TK2MSFTN GP02.phx.gbl...
Boo,
I view Return as returning to whence I came. Which as Michael suggests is
common across most other languages.

Optionally a value may be included when I return to whence I came.

Unfortunately I am inconsistent on always using Return; I occasionally use
Exit Sub... Which could be considered an odd-ball solution...

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
.NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"GhostInAK" <gh*******@gmai l.comwrote in message
news:c7******** *************** ***@news.micros oft.com...
| Hello tshad,
|
| There is no difference in the IL output from "Return" and "Exit Sub"
when
| used in a sub. However, for readability I would suggtest using Exit
Sub.
| Return denotes pushing a value back to the caller, which since a sub
doesnt
| have a return value, makes for a less clear intent.
|
| -Boo
|
| Is there any difference between Return and Exit Sub?
| >
| I have some code that uses both when I have an error in my Sub.
| >
| Thanks,
| >
| Tom
| >
|
|


Jul 21 '06 #9
Cor,

I assume you mean

Exit For
Exit Do
Exit ...

Yes, this is nice, but when I always comment the inner exits. Otherwise,
they are tough to track.

Mike.

"Cor Ligthert [MVP]" <no************ @planet.nlwrote in message
news:uK******** ******@TK2MSFTN GP05.phx.gbl...
Michael,

VBNet is the only language where I am/was easily able to go deeper than 8
levels. That because of the nice descriptions of the levels.

:-)

Cor

"Michael D. Ober" <obermd.@.alum. mit.edu.nospams chreef in bericht
news:V6******** ********@newsre ad3.news.pas.ea rthlink.net...
>>
"Cor Ligthert [MVP]" <no************ @planet.nlwrote in message
news:%2******* *********@TK2MS FTNGP04.phx.gbl ...
>>Herfried,

Well, you could interpret 'Return' either as "Return something" or
"Return
>to something".

It is not about holidays.

It is about a nothing returning method in VBNet what has the name Sub.

In far past when stacks did not yet be used, there was set a return
address
>>mostly as last command in a method.

I never investigated this but in a normal modern system, the sub ends
and
the program goes on in the one higher stack; one position after where it
was
>>calling the Sub.

There is an implicit return at the end of a Sub. As far as using Exit
Sub
or Return, I have switched to Return as most other languages use Return
for
this purpose. VB was the only language to not use return in this manner
because the BASIC return statement indicated the return from a GOSUB
statement.

Mike.
>>>
:-)

Cor

"Herfried K. Wagner [MVP]" <hi************ ***@gmx.atschre ef in bericht
news:eF****** ********@TK2MSF TNGP02.phx.gbl. ..
"GhostInAK" <gh*******@gmai l.comschrieb:
There is no difference in the IL output from "Return" and "Exit Sub"
when
>>>used in a sub. However, for readability I would suggtest using Exit
Sub.
>>>Return denotes pushing a value back to the caller, which since a sub
doesnt have a return value, makes for a less clear intent.

Well, you could interpret 'Return' either as "Return something" or
"Return
>to something".

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>




Jul 21 '06 #10

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

Similar topics

1
7772
by: Tung Wai Yip | last post by:
I've build the following utility. It works so far but I want to make sure I'm doing the right thing. I am running Python 2.3 on windows 2000. def execute(cmd): """ execute cmd in sub-process, pipe output to stdout, return exit status (None means OK) """
27
2664
by: Maximus | last post by:
Hi, I was just wondering, is it good to use return without arguments in a void function as following: void SetMapLayer() { if( !Map ) return; layer = LAYER_MAP; }
4
5280
by: John Black | last post by:
Hi, I wonder what is the difference between ending the main() with and without exit(0)? My code is like this flow, class ClassA{ ClassB* cb; int toExit();
0
1938
by: Paul Patrick | last post by:
Keep getting this error when I input the following command gcj -o filename.java --main=filename filename.java Any ideas on what the problem might be?
11
29728
by: Peter Steele | last post by:
I have a Windows application written in C# that I want to return a non-zero exit code when it it run. The problem is that as a Windows application, there doesn't seem to be a way to control this. The value returned by the Main function has no impact on the value returned by the application. Windows applications exit immediately, leaving their windows still open. Is there a way to change the value a Windows application exits with. Basically...
3
11860
by: John Williams | last post by:
VB .Net 2003, .Net Framework 1.1, Windows XP Pro SP1 I've written a console application which I run as a scheduled task. How do I return an exit status value (or string) from the application so that the status is displayed in the Status column of the Scheduled Tasks window? I've tried the following methods, and the console app definitely runs (as shown by the Last Run Time in the Scheduled Tasks window), however the Status column is...
4
3622
by: Wardeaux | last post by:
Hope this is easy... I have a simple winform app that does some work and then exits... I need to return a value to the calling app/process to indicate completion status... what's the fastest/easiest way to do that? MTIA wardeaux
20
3590
by: lovecreatesbeauty | last post by:
Hello experts, Is the following code snippet legal? If it is, how can exit() do the keyword return a favor and give a return value to the main function? Can a function call (or only this exit(n)) statement provide both function call and return features of the C programming language? /* headers omitted */ int main (void)
3
55680
by: asearle | last post by:
Hallo everyone, I have a perl script which can return error codes. I have done this with, for example, 'exit 11;', which would (I imagine) send the exit code 11 (instead of 0) back to the calling program. I would now like to check that my error codes are being returned correctly and so wanted to write a short script to test this. Here I considered using the following ... $checkexitcode = system ("perl myscript.pl"); but believe...
11
2280
by: =?Utf-8?B?U3RldmVEQjE=?= | last post by:
Hi all. I'm using VS 2008 Express C++. I created a console application back in 1999, and updated it for VC++ 6.0 in 2001. I've updated again this past month, and have found enough differences that I now need to use a different exit routine. In 2001, I could use a basic escape with a do {}while(ch!= 27); Now that apparently does not work. So, how do I exit a function now with C++ 2008 express?
0
9145
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9010
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8853
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7703
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6515
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4611
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2319
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1992
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.