Command, Command$ Function


Returns the argument portion of the command lineP80XWW used to launch Microsoft Visual Basic.




Command returns a Variant8PHEAW3; Command$ returns a String.

When Visual Basic is launched from the command line, any portion of the command line that follows /CMD is passed to the program as the command-line argument.  In the following example, cmdlineargs represents the argument information returned by the Command[$] function.

     VB /CMD cmdlineargs

For applications developed with Visual Basic (compiled to an .EXE file), Command[$] returns any argument(s) that appears after the name of the application on the command line.  For example:

     myapp  cmdlineargs

In the code window, you can change the text returned by Command[$] by choosing Project from the Options menu.

Command, Command$ Functions Example

The example uses Command to display the arguments on the command line.  To try this example, paste the code into the Declarations section of a form.  Then press F5 and click the form.


Sub Form_Click ()

   Dim Msg                         ' Declare variable.

   If Command = "" Then            ' If no command line.

      Msg = "There is currently no command-line string."

   Else                            ' Put command line into message.

      Msg = "The command-line string is: '" & Command & "'"

   End If

   MsgBox Msg                      ' Display message.

End Sub