Recieving parameters on the command line

Posted on 2006-04-12
Last Modified: 2011-09-20
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?
Question by:HKComputer
    LVL 39

    Assisted Solution

    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
    LVL 9

    Assisted Solution

    by:Naveen Swamy
    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

    LVL 9

    Accepted Solution

    this will return the parameters as a string array

    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"
    LVL 4

    Author Comment

    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.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now