VB Command Line?

I'm having trouble processing the VB Command line (or at least I'm confused).

My "test" code is:

Module Module1

    Sub Main()

        Dim NumArgs As Integer
        Dim Arguments As String()

        Arguments = Environment.CommandLine.Split

        NumArgs = Arguments.Count


        For Each argument In Arguments

    End Sub

End Module

What I see is the count includes a "blank" entry.  The first entry shown is the name of the executable, and then a blank, and then the "real" arguments.  What's up with the blank?
Gene KlamerusTechnical ArchitectAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
I'm not entirely sure about this behavior, but I have a feeling you are making this a bit more involved than it has to be  = )

Instead of splitting the CommandLine value, you can call GetCommandLineArgs to get the parameters passed to your application:

Arguments = Environment.GetCommandLineArgs()

Open in new window

...and that should give you what you seek. However, my personal preference would be to use the built in string array that you get with Main functions:

Sub Main(ByVal args() As String)

Open in new window

...and your code becomes:

Module Module1

    Sub Main(ByVal args() As String)

        For Each argument In args

    End Sub

End Module

Open in new window

Now with this approach, you don't get the command that was executed, but you could glean that from your previous logic and checking the first argument:

Dim command As String = Environment.GetCommandLineArgs()(0)

Open in new window

Just something for you to ponder  = D

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

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.