CommandParm

Description

Retrieves the argument string, if any, that followed the program name when the application was executed.

Syntax

CommandParm ( )

Return value

String.

Returns the application's argument string if it succeeds and the empty string ("") if it fails or if there were no arguments.

Usage

Command arguments can follow the program name in the command line of a Windows program item or in the Program Manager's Run response window. For example, when the user chooses File>Run in the Program Manager and enters:

MyAppl C:\EMPLOYEE\EMPLIST.TXT

CommandParm retrieves the string C:\EMPLOYEE\EMPLIST.TXT.

If the application's command line includes several arguments, CommandParm returns them all as a single string. You can use string functions, such as Mid and Pos, to parse the string.

You do not need to call CommandParm in the application's Open event. Use the commandline argument instead.

Examples

These statements retrieve the command line arguments and save them in the variable ls_command_line:

string ls_command_line
ls_command_line = CommandParm()

If the command line holds several arguments, you can use string functions to separate the arguments. This example stores a variable number of arguments, obtained with CommandParm, in an array. The code assumes each argument is separated by one space. For each argument, the Pos function searches for a space; the Left function copies the argument to the array; and Replace removes the argument from the original string so the next argument moves to the first position:

string ls_cmd, ls_arg[]
integer i, li_argcnt
 
// Get the arguments and strip blanks
// from start and end of string
ls_cmd = Trim(CommandParm())
 
li_argcnt = 1
DO WHILE Len(ls_cmd) > 0
    // Find the first blank
    i = Pos( ls_cmd, " ")
 
    // If no blanks (only one argument),
    // set i to point to the hypothetical character
    // after the end of the string
    if i = 0 then i = Len(ls_cmd) + 1
 
    // Assign the arg to the argument array.
    // Number of chars copied is one less than the
    // position of the space found with Pos
    ls_arg[li_argcnt] = Left(ls_cmd, i - 1)
 
    // Increment the argument count for the next loop
    li_argcnt = li_argcnt + 1
 
    // Remove the argument from the string
    // so the next argument becomes first
    ls_cmd = Replace(ls_cmd, 1, i, "")
LOOP