Click here to Skip to main content
15,896,912 members
Home / Discussions / Visual Basic
   

Visual Basic

 
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 
Questionroblem with MySQL 1.0 .NET Connector using VB.NET Window Form Application Pin
drexler_kk4-Jun-08 23:08
drexler_kk4-Jun-08 23:08 
AnswerRe: roblem with MySQL 1.0 .NET Connector using VB.NET Window Form Application Pin
Noctris5-Jun-08 12:24
Noctris5-Jun-08 12:24 
GeneralRe: Problem with MySQL 1.0 .NET Connector using VB.NET Window Form Application Pin
drexler_kk5-Jun-08 15:17
drexler_kk5-Jun-08 15:17 
GeneralRe: Problem with MySQL 1.0 .NET Connector using VB.NET Window Form Application Pin
Noctris10-Jun-08 12:50
Noctris10-Jun-08 12:50 
AnswerRe: roblem with MySQL 1.0 .NET Connector using VB.NET Window Form Application Pin
SteveNY11-Jun-08 5:37
SteveNY11-Jun-08 5:37 
AnswerRe: roblem with MySQL 1.0 .NET Connector using VB.NET Window Form Application Pin
SteveNY11-Jun-08 6:56
SteveNY11-Jun-08 6:56 
Questionscalable picture box Pin
iain65944-Jun-08 23:07
iain65944-Jun-08 23:07 
AnswerRe: scalable picture box Pin
JoeSharp4-Jun-08 23:40
JoeSharp4-Jun-08 23:40 
GeneralRe: scalable picture box Pin
iain65945-Jun-08 4:13
iain65945-Jun-08 4:13 
AnswerRe: scalable picture box Pin
Christian Graus5-Jun-08 4:51
protectorChristian Graus5-Jun-08 4:51 
QuestionHow to set default credentials on Vista using .Net ? Pin
Rizwan Bashir4-Jun-08 22:46
Rizwan Bashir4-Jun-08 22:46 
Questioncreate word document with open xml format Pin
zvedu0074-Jun-08 22:21
zvedu0074-Jun-08 22:21 
QuestionPassing Object Arrays as arguments and changing it. Pin
Joakim Nygren4-Jun-08 21:14
Joakim Nygren4-Jun-08 21:14 
AnswerRe: Passing Object Arrays as arguments and changing it. Pin
Johan Hakkesteegt5-Jun-08 3:44
Johan Hakkesteegt5-Jun-08 3:44 
Questionto get reply in child node Pin
Shanmugapriya.G4-Jun-08 20:44
Shanmugapriya.G4-Jun-08 20:44 
AnswerRe: to get reply in child node Pin
Ashfield4-Jun-08 21:12
Ashfield4-Jun-08 21:12 

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.