Program Flow Statements

 <  Day Day Up  >  

There are two statements that can control the overall program flow. The End statement causes program execution to end. This statement may not be used in class libraries (i.e., DLLs), because they are not executable. For example:

 Module Test   Sub Main()     Dim x As Integer     While True       x = CInt(Console.ReadLine())       If x = 0 Then         End       End If     End While   End Sub End Module 

Advanced

When an End statement is executed, the Finalize method on classes will be run before shutdown, but the Finally blocks of any currently executing Try statements will not be executed


The Stop statement also causes program execution to end, but will also transfer control to a debugger if one is present. Stop is primarily useful when you are developing a program that needs to run for some time before debugging begins. For example:

 Module Test   Sub Main()     Dim x As Integer     While x > 0       x = CInt(Console.ReadLine())       ' When x = -1, break into the debugger.       If x = -1 Then         Stop       End If     End While   End Sub End Module 

Style

Because it is easy to forget to remove Stop statements from source code, setting breakpoints in the debugger is usually preferable to using Stop statements.


 <  Day Day Up  >  


The Visual Basic .NET Programming Language
The Visual Basic .NET Programming Language
ISBN: 0321169514
EAN: 2147483647
Year: 2004
Pages: 173
Authors: Paul Vick

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net