Click here to Skip to main content
15,920,503 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Mailing send error due to ... !!! Pin
John Kh5-Jun-08 19:02
John Kh5-Jun-08 19:02 
QuestionNavigation Pane Pin
felipeoroz5-Jun-08 5:16
felipeoroz5-Jun-08 5:16 
AnswerRe: Navigation Pane Pin
Christian Graus5-Jun-08 5:42
protectorChristian Graus5-Jun-08 5:42 
QuestionGetting error while using WSAStartup method Pin
Chaitanya kumar CVSS5-Jun-08 1:54
Chaitanya kumar CVSS5-Jun-08 1:54 
Questiondisplay information on list box when treeview node is selected Pin
Mamphekgo Bahula5-Jun-08 1:24
Mamphekgo Bahula5-Jun-08 1:24 
AnswerRe: display information on list box when treeview node is selected Pin
Ashfield5-Jun-08 3:21
Ashfield5-Jun-08 3:21 
AnswerRe: display information on list box when treeview node is selected Pin
Anubhava Dimri5-Jun-08 18:44
Anubhava Dimri5-Jun-08 18:44 
QuestionHOW TO CREATE YOUR OWN MEDIA PLAYER!!!!!!!!!!!!!!!! Pin
spinky5-Jun-08 1:12
spinky5-Jun-08 1:12 
AnswerRe: HOW TO CREATE YOUR OWN MEDIA PLAYER!!!!!!!!!!!!!!!! Pin
Johan Hakkesteegt5-Jun-08 3:16
Johan Hakkesteegt5-Jun-08 3:16 
GeneralRe: HOW TO CREATE YOUR OWN MEDIA PLAYER!!!!!!!!!!!!!!!! Pin
MarkB7775-Jun-08 21:05
MarkB7775-Jun-08 21:05 
AnswerRe: HOW TO CREATE YOUR OWN MEDIA PLAYER!!!!!!!!!!!!!!!! Pin
Ashfield5-Jun-08 3:24
Ashfield5-Jun-08 3:24 
AnswerRe: HOW TO CREATE YOUR OWN MEDIA PLAYER!!!!!!!!!!!!!!!! Pin
Christian Graus5-Jun-08 4:10
protectorChristian Graus5-Jun-08 4:10 
GeneralRe: HOW TO CREATE YOUR OWN MEDIA PLAYER!!!!!!!!!!!!!!!! Pin
MarkB7775-Jun-08 21:07
MarkB7775-Jun-08 21:07 
QuestionRunning VB.Net with Crystal Reports load problem Pin
Central_IT4-Jun-08 23:53
Central_IT4-Jun-08 23:53 
AnswerRe: Running VB.Net with Crystal Reports load problem Pin
ChandraRam5-Jun-08 0:02
ChandraRam5-Jun-08 0:02 
GeneralRe: Running VB.Net with Crystal Reports load problem Pin
Central_IT5-Jun-08 0:09
Central_IT5-Jun-08 0:09 
GeneralRe: Running VB.Net with Crystal Reports load problem Pin
ChandraRam5-Jun-08 0:15
ChandraRam5-Jun-08 0:15 
AnswerRe: Running VB.Net with Crystal Reports load problem Pin
Anubhava Dimri5-Jun-08 18:54
Anubhava Dimri5-Jun-08 18:54 
QuestionWhat is the difference between Return and Exit Sub? Pin
epp11234-Jun-08 23:13
epp11234-Jun-08 23:13 
AnswerRe: What is the difference between Return and Exit Sub? Pin
Jay Royall4-Jun-08 23:33
Jay Royall4-Jun-08 23:33 
GeneralRe: What is the difference between Return and Exit Sub? Pin
Guffa5-Jun-08 23:32
Guffa5-Jun-08 23:32 
AnswerRe: What is the difference between Return and Exit Sub? Pin
Kevin Brydon4-Jun-08 23:56
Kevin Brydon4-Jun-08 23:56 
AnswerRe: What is the difference between Return and Exit Sub? Pin
~Khatri Mitesh~5-Jun-08 2:19
~Khatri Mitesh~5-Jun-08 2:19 
AnswerRe: What is the difference between Return and Exit Sub? Pin
supercat95-Jun-08 6:11
supercat95-Jun-08 6:11 
When used within a function, the return statement allows a value to be specified; that value will be given to the calling program.

Within function 'foo', for example, one could replace:
foo = 5
Exit Sub
with
Return 5
The Return statement may also be used without an argument, in which case it will behave like 'Exit Sub'. Earlier versions of VB required "Exit Sub", while other languages use "Return". Generally, I prefer Return, though that may be a matter of style. Note that in prior versions of VB, Return was a valid statement, but it meant something very different from in vb.net.

As for whether performing a 'Return' in the middle of a function constitutes good structured programming, I would suggest that there are cases where it is appropriate and places where it is not. If a sub or function will sometimes do nothing, it's better to use an 'early abort' test and return statement than to enclose the entire routine in a giant 'if'. On the other hand, a Return statement in the middle of a routine that generally runs to the end can sometimes cause confusion.

The biggest thing to watch out for, historically, has been with routines that begin some action that needs to be cleaned up. An early-exit test which skips the routine before it does anything requiring cleanup poses no problem, but returns in the middle can pose a problem. If the routine has allocated any resources, they need to be deallocated before the routine exits. This has typically been handled by putting some cleanup code before every Return or Exit statement. Such an approach could frequently lead to bugs, if cleanup requirements changed but not all the cleanup code was adjusted.

In a modern language like vb.net, structures like Try/Finally blocks and Using statements can alleviate some of the cleanup issues associated with mid-function exits. On the other hand, they can also cause code to be executed in confusing sequence. If a 'Return' or 'Exit Sub' is performed within a Try/Finally block, the 'Finally' clause will be executed, but code following the block will not.
AnswerRe: What is the difference between Return and Exit Sub? Pin
puffdaddy4115-Jun-08 19:30
puffdaddy4115-Jun-08 19:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.