COMMAND$ function

Purpose: COMMAND$ returns the command line tail, that is, a character string containing everything typed on the command line after the filename that started the program.


 Syntax 1:

 RetStr$ = COMMAND$

 Parameters:

  • RetStr$ Returned string containing everything typed on the command line after the filename that started the program.

Example:


 DIM RetStr$
 RetStr$ = COMMAND$
 PRINT RetStr$


 Syntax 2:

 RetStr$ = COMMAND$(ArgCount%)

 Parameters:

  • RetStr$ Returned string containing the argument at the ArgCount% position of the command line string.
  • ArgCount% Integer representing position of the argument returned in RetStr$ in the command line string. This value is zero based. COMMAND$(0) will return the name of the executable.

Example:


 DIM cmd$
 DIM i AS INTEGER
 
 cmd$ = COMMAND$
 
 PRINT "Full command tail: [", cmd$, "]"
 PRINT "The executable name is [", COMMAND$(0), "]"
 
 i = 1
 
 cmd$ = COMMAND$(i)
 
 WHILE cmd$ <> ""
   PRINT "Argument", i, " is [", cmd$, "]"
   i++
   cmd$ = COMMAND$(i)
 WEND
 
 PRINT "Total arguments:", i - 1

Using COMMAND$ to detect drag and dropped files

COMMAND$ is drag and drop aware and can capture the path and name of a file that is drag and dropped or copied and pasted on to its executable.

The following example will capture the path\filename of any file dropped on it and show a Message Box with, and print to a file, the path\filename of the dropped file.


 DIM Filename$
 DIM A$

 'Use this to write to Current folder
 'Filename$ = CurDir$ &"\TestFile.txt"
 'Use this to write to exe folder
 Filename$ = APPEXEPATH$ &"TestFile.txt"

 OPEN Filename$ FOR APPEND AS FP1
 A$ = COMMAND$
 MSGBOX A$
 FPRINT FP1, A$
 CLOSE FP1

BCX Console Sample Programs using statement function.

S06.bas, S44.bas, S47.bas, S48.bas, S64.bas, S65.bas, S67.bas, S68.bas, S71.bas, S73.bas, S74.bas, S77.bas, S96.bas, S98.bas, S103.bas, S105.bas, S141.bas,