how to read console input

i'm trying to make a console app that basically works like this:

user types app name in console, example PrintDoc
following PrintDoc is a url and number, so it might look something like this

PrintDoc http://www.google.com 3

that basically tells the program to print 3 copies of http://www.google.com

i'm not sure how to pull the http://www.google.com and the 3 when the user inputs it, any suggestions?
i'm very new to vb programming, this is a .net app

thanks
LVL 4
LTY83Asked:
Who is Participating?
 
Erick37Commented:
Much simpler... I forgot you could just pass in the array directly int Main()

Module Module1

    Sub Main(ByVal args() As String)
        'Dim args() As String = GetCommandLineArgs()
        If IsArray(args) Then
            Dim i As Integer
            For i = LBound(args) To UBound(args)
                'print out each command line arg
                Console.WriteLine(args(i))
            Next
        End If
    End Sub


End Module
0
 
Erick37Commented:
Use the Command() function to read in the command line parameters.
Simple demo using the function GetCommandLineArgs() from MS help.

Module Module1

    Sub Main()
        'Read command line args (if any)
        Dim args() As String = GetCommandLineArgs()
        'Test to see if any args passed in
        If IsArray(args) Then
            Dim i As Integer
            For i = args.GetLowerBound(0) To args.GetUpperBound(0)
                'print out each command line arg
                Console.WriteLine(args(i))
            Next
        End If
    End Sub

    'This function taken from MS on-line help files
    Function GetCommandLineArgs() As String()
        ' Declare variables.
        Dim separators As String = " "
        Dim commands As String = Microsoft.VisualBasic.Command()
        Dim args() As String = commands.Split(separators.ToCharArray)
        Return args
    End Function


End Module
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.