Results 1 to 13 of 13

Thread: What is COMMAND()?

  1. #1

    Thread Starter
    Lively Member James Bond 007's Avatar
    Join Date
    May 2000
    Location
    London
    Posts
    116
    This is the example that MSDN provided for COMMAND().

    What is COMMAND() and how do you use this Function below?

    Thanks

    Code:
    Function GetCommandLine(Optional MaxArgs)
      'See if MaxArgs was provided.
      If IsMissing(MaxArgs) Then MaxArgs = 10
      'Make array of the correct size.
      ReDim ArgArray(MaxArgs)
      Dim InArg, NumArgs
      NumArgs = 0: InArg = False
      
      'Get command line arguments.
      Dim CmdLine, CmdLnLen
      CmdLine = Command()
      CmdLnLen = Len(CmdLine)
       
      Dim C, I
      'Go thru command line one character
      'at a time.
      For I = 1 To CmdLnLen
         C = Mid(CmdLine, I, 1)
         'Test for space or tab.
         If (C <> " " And C <> vbTab) Then
            'Neither space nor tab.
            'Test if already in argument.
            If Not InArg Then
            'New argument begins.
            'Test for too many arguments.
               If NumArgs = MaxArgs Then Exit For
               NumArgs = NumArgs + 1
               InArg = True
            End If
            'Concatenate character to current argument.
            ArgArray(NumArgs) = ArgArray(NumArgs) & C
         Else
            'Found a space or tab.
            'Set InArg flag to False.
            InArg = False
         End If
      Next I
       
      'Resize array just enough to hold arguments.
      ReDim Preserve ArgArray(NumArgs)
      'Return Array in Function name.
      GetCommandLine = ArgArray()
    End Function
    License to Program

    007

  2. #2
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    Command() just returns all the command line parameters. If your program is called myprog.exe and the user typed in dos:
    myprog hello
    then Command() would return "hello"

  3. #3
    Guest
    well, when you make your filetype associated with your program, Command returns the path of the file that is being opened, the problem is, it has quotes around the name so you have to replace the quotes with spaces, then trim the spaces(via Replace and Trim).

  4. #4

    Thread Starter
    Lively Member James Bond 007's Avatar
    Join Date
    May 2000
    Location
    London
    Posts
    116
    Can you show me how the example above works? or make your own example and show me.

    thank you Oetje and Denniswrenn
    License to Program

    007

  5. #5
    Guest
    Code:
    Private Sub Form_Load()
        Dim FF As Integer
        Dim FName As String
        FF = FreeFile
    
            If Command$ <> "" Then
                FName = Replace(Command$, Chr$(34), " ")
                FName = Trim$(FName)
                FF = FreeFile
                Open FName For Input As FF
                    txtText = Input(LOF(FF), FF)
                Close FF
            End If
    End Sub

  6. #6

    Thread Starter
    Lively Member James Bond 007's Avatar
    Join Date
    May 2000
    Location
    London
    Posts
    116

    Question

    Thanks Dennis but how do i test this? I ran the program but it didn't do anything.

    And why would someone use COMMAND()?

    [Edited by James Bond 007 on 08-21-2000 at 02:55 AM]
    License to Program

    007

  7. #7
    Guest
    that is because you have to associate a file type with your program.

    then double click the filetype(after it is associated) and it should work.

    see this Tip on details how to associate a filetype with your program.

  8. #8
    Guest
    OH: I forgot one thing, you are going to have to make an exe out of your program to associate it....

    a quick way to associate your program with a file is to make a file with an unknown extension,
    for example....

    MyFile.007

    then double click that file, a box saying
    "Open With..." will appear,
    there will also be a list box, your program shouldnt be in the list box, instead, choose to browse for your program, then tick the box that says "always open with this program"
    and `viola

    simple.....

  9. #9

    Thread Starter
    Lively Member James Bond 007's Avatar
    Join Date
    May 2000
    Location
    London
    Posts
    116
    What am I suppose to associate with?

    I tried Ojtie and it gave me an error of 53.
    License to Program

    007

  10. #10
    Guest
    The reason one would use Command is so you can retrieve the command line parameters, for example, if you wanted to run your program from a dos prompt and typed


    c:\windows\desktop\pathtofile>MyFile -param

    you would check for "-param" and if it was a valid parameter you would do something.

    you can look at an example of a program using command line parameters here:
    http://www.winamp.com/nsdn/winamp2x/dev/sdk/api.jhtml

    the Command function can also be used for what I described to you,
    for getting the path to a file that was double clicked.

  11. #11

    Thread Starter
    Lively Member James Bond 007's Avatar
    Join Date
    May 2000
    Location
    London
    Posts
    116

    Thumbs up So young and talented.

    Thanks Dennis! I finally got working when you gave me that example with a test file call myfile.007 and associated with my own program.

    I put in some info in myfile.007 and double click on it, and my program came up with that info. Is that what it suppose to do?

    Thanks for your help.
    License to Program

    007

  12. #12
    Guest

    Talking Yep!

    I put in some info in myfile.007 and double click on it, and my program came up with that info. Is that what it suppose to do?
    that means it worked

    pat yourself on the bad Mr. Bond, because... well i dont know why you should pat yourself on the back, but just do it


  13. #13
    Guest
    You can also retrieve multiple command line arguments by using the Split() function.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width