Command-Line Arguments

Team-Fly    

 
Application Development Using Visual Basic and .NET
By Robert J. Oberg, Peter Thorsteinson, Dana L. Wyatt
Table of Contents
Chapter 4.  VB.NET Essentials, Part II


Command-line arguments are provided as an array of String objects obtained via the Environment.GetCommandLineArgs method. [1] An integer exit code can be returned to the operating system via the Environment.ExitCode property to indicate the overall success or failure of the program upon termination. This is useful for controlling batch scripts or other programs that execute your VB.NET program. The Environment class provides access to other useful information, such as environment strings and the current directory. This example is provided in the AccessEnvironmentInfo directory.

[1] To establish command-line arguments within Visual Studio, right-click on the project node (not the solution node) in Solution Explorer, choose properties, and select the Debugging under Configuration Properties. Then enter the desired space-delimited command-line argument text into the command-line arguments text field. Then, when you run the program from within Visual Studio, these command-line arguments will be in effect.

 graphics/codeexample.gif Module AccessEnvironmentInfo  Public Sub Main()  Dim cmds() As String = _  Environment.GetCommandLineArgs()  Dim cmdArg As String       For Each cmdArg In cmds          Console.WriteLine(cmdArg)       Next  Environment.ExitCode = 0  '0 usually means success    End Sub End Module 

Team-Fly    
Top
 


Application Development Using Visual BasicR and .NET
Application Development Using Visual BasicR and .NET
ISBN: N/A
EAN: N/A
Year: 2002
Pages: 190

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