Deal with Command Line Arguments : Command Line « Development « VB.Net






Deal with Command Line Arguments

Deal with Command Line Arguments
 
Imports System
Imports System.Configuration
Imports System.Resources ' Resource readers

Public Class MainClass
    
    Shared Sub Main(ByVal args As String())
        Dim flag As Boolean = False
        Dim name As String = ""
        Dim number As Integer = 0

        Dim i As Integer
        For i = 0 To args.Length - 1
            Select Case args(i)
                Case "/flag"
                    flag = True
                Case "/name"
                    i += 1
                    name = args(i)
                Case "/number"
                    i += 1
                    number = Integer.Parse(args(i))
                Case Else
                    Console.WriteLine("invalid args!")
                    Exit Sub
            End Select
        Next

        Console.WriteLine(flag.ToString(), "Flag")
        Console.WriteLine(name, "Name")
        Console.WriteLine(number.ToString(), "Number")


    End Sub
End Class
           
         
  








Related examples in the same category

1.Get Command lineGet Command line
2.Get Command line arguments from System.Environment
3.Demonstrates the GetEnvironmentVariables method.
4.Set System.Environment.ExitCode