Programmer's Corner - Visual Basic .NET Source Code Sample

Backup and Security Solutions 10% off all products with promo code: VISI-P1YR
Get the Programmer's Corner FireFox Search Plug-In

Processing the Command Line Arguments for VB.Net - Visual Basic .NET

Eric D. Burdo

http://thenxtstep.blogspot.com/

         

         

This small section of code gives you the basics on how to process the command line arguments in VB.Net.

The command line arguments in VB.Net are an array... so you can use simple array commands to get each item. Then process them the way you want.





    Public Sub Main(ByVal sArgs() As String)
        'Note the declaration of the Sub Main line
        'It has the sArgs parameter.  This parameter is handled by
        'the system, and contains any command line arguments.

        If sArgs.Length = 0 Then                'If there are no arguments
            Console.WriteLine("Hello World! <-no arguments passed->") 'Just output Hello World
        Else                                    'We have some arguments		
            Dim i As Integer = 0

            While i < sArgs..Length             'So with each argument
                Console.WriteLine("Hello " & sArgs(i) & "!") 'Print out each item
                i = i + 1                       'Increment to the next argument
            End While

        End If

    End Sub