Flylib.com

Books Software

 
 
 

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

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
 
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


Summary

In this chapter we examined some standard types, such as String , StringBuilder , and Array . We covered some additional topics concerning methods , including parameter passing, variable-length parameter lists, and method overloading. We saw how to handle command-line arguments in VB.NET. We looked at a number of common utility functions in VB.NET, which are found in either the System namespace or the Microsoft.VisualBasic namespace.

A number of examples pertained to a hotel reservation system. In the next chapter, we will study object-oriented programming in VB.NET, and we will extend our hotel reservation example to a case study, which will be continued throughout the rest of the book. We will also look at exception handling in VB.NET.


Team-Fly    
Top