Recieving parameters on the command line

I'm trying to program a very elementary program (to work with another software vendors program) that needs to be able to accept two parameters from the command line.  

The instructions I have from the software vendor say: When [TheirSoftware] 'calls' or invokes [MyProgram], it passes two parameters on the command line.  The first parameter is the exact name and path of the [first text file generated by TheirSoftware] and the second paraemter is the exact name and path of the [text file to be passed back to TheirSoftware].

So my program will be invoked like this:

MyProgram c:\somedirectory\original.txt c:\somedirectory\new.txt

How do I read or use the parameters that are being passed to MyProgram?
LVL 4
HKComputerAsked:
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.

appariCommented:
add a Main sub in a module as follows

      Sub main(ByVal ParamArray args() As String)

       
      end sub

now you will get all the command line arguments in the array args. set this sub main as your startup object
0
Naveen SwamyYash Infinite Solutions Private LimitedCommented:
Returns the argument portion of the command line used to start Visual Basic or an executable program developed with Visual Basic. The My feature provides greater productivity and performance than the Command function. For more information, check out My.Application.CommandLineArgs Property.

Function GetCommandLineArgs() As String()
   ' Declare variables.
   Dim separators As String = " "
   Dim commands As String = Microsoft.VisualBasic.Interaction.Command()
   Dim args() As String = commands.Split(separators.ToCharArray)
   Return args
End Function

0
tolgaongCommented:
Environment.GetCommandLineArgs
this will return the parameters as a string array
so:

dim CLP as string() = Environment.GetCommandLineArgs()
first element is always your programs name with full path
and the others are the parameters youhave sent

MyProgram c:\somedirectory\original.txt c:\somedirectory\new.txt

if you have spaces in the parameters
MyProgram c:\some directory\original.txt c:\some directory\new.txt

you should identify the parameters with quetation markas
MyProgram "c:\some directory\original.txt" "c:\some directory\new.txt"
0

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
HKComputerAuthor Commented:
I believe that all three of the above answers are correct.  I found the last one the easiest to understand and therefore I used it.  Thanks for you help.
0
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.