Link to home
Start Free TrialLog in
Avatar of rutledgj
rutledgj

asked on

command line arguments in vb

dumb and simple question. I've created a console app and want to read in command line arguements.  Main looks like this:

 Dim s() As String = System.Environment.GetCommandLineArgs()

        For i As Integer = 1 To UBound(s)
            Console.WriteLine(s(i) & vbCrLf)
        Next

        Console.ReadLine()

in properties/debugger I'm passing in this:

"hello","world","you","are","cruel"

when I run it s(1) contains the entire list of words. I expected each word to be in its own array position.

Can someone tell me what I'm doing wrong here?
Avatar of Frosty555
Frosty555
Flag of Canada image

Try using the My.Application.CommandLineArgs property instead, it is a collection of arguments tokenized by whitespace like you are expecting.

http://msdn.microsoft.com/en-us/library/z2d603cy(v=vs.90).aspx
ASKER CERTIFIED SOLUTION
Avatar of lludden
lludden
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oh sorry I misread you.

The reason why you are seeing the command line arguments all in one shot is because command line arguments are tokenized by *whitespace*, not by commas.

So when you put in the arguments

  "hello","world","you","are","cruel"

There is no whitespace in that line, so it is considered to only be one argument. This is the behavior for all applications in Windows. If you wanted to accept command line arguments in that format you'd ned to parse it by comma yourself.

You probably meant to do this:

"hello" "world" "you" "are" "cruel"