parsing the command line arguments

Posted on 2004-11-01
Last Modified: 2010-05-02
How do you read values passed as a command line argument in vb6 applications. the application would be called like shown below. I would like to get the three arguments that are passed with the exe. How do i do that vb 6. thanks in advance.

C:\parser.exe JU1991020005 940604707218.txt  940604707218.idx
Question by:sony1464
    LVL 35

    Expert Comment

    by:[ fanpages ]

    Query the Command$ variable in your VB code.

    In the above example, it will contain "JU1991020005 940604707218.txt  940604707218.idx".


    LVL 8

    Expert Comment

    I think you can get by using the command function.

    sub frmmain_load()
       frmmain.text1 = command
    end sub
    LVL 6

    Expert Comment

    LVL 24

    Accepted Solution

    Sub Form_load()
      Dim CommandArgs
      CommandArgs = Split(Command(), " ")
      'CommandArgs(0) will contain your first argument
      'CommandArgs(1) will contain your second argument
    End Sub
    LVL 3

    Author Comment


    i tried hes's example and it worked great .... now how do i get the filename without the extension from the second argument and save it in the application diresctory as filaname.doc...i really appreciate such a quick reponse....

    for the above example i want a file called 940604707218.doc to be created in the application directory.
    LVL 8

    Assisted Solution

    Assuming your still using the above, untested.

    Sub Form_load()
      Dim CommandArgs
      Dim cmdFilename as string

      CommandArgs = Split(Command(), " ")
      CommandArgs(0) will contain your first argument
      CommandArgs(1) will contain your second argument
       cmdfilename =  left(CommandArgs(1), len(CommandArgs(1))-3)

       Open app.path & "\" & cmdfilename & "doc" For output As #1
             Print #1, "File created."
       Close #1

    End Sub

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
    Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    933 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

    15 Experts available now in Live!

    Get 1:1 Help Now