PRB: RUN Command Won't Work with Variables Prefixed with "M."

ID: Q121823

The information in this article applies to:

SYMPTOMS

Attempting to use a variable with an "M." prefix doesn't work when you use the variable and macro substitution in conjunction with the RUN command.

CAUSE

In FoxPro, the period is used as the macro termination character when used in combination with literal strings. FoxPro sees the "M." in the variable name as indicating a request to expand the contents of a variable called M and concatenate it with the rest of the string it follows. Because there is no variable named M, the command fails.

RESOLUTION

When a macro directly precedes a literal string, use the terminator. If you don't, the evaluator attempts to look for a variable name matching the characters between the ampersand and the first character that would be invalid in a variable name, such as a space or a quotation mark.

To work around this behavior, declare a working variable as PRIVATE within your procedure or function that executes the RUN command and use an indirect approach to achieve the same result. The following code demonstrates this:

   PROCEDURE MYPROC
   PRIVATE TOBERUN

   TOBERUN = M.SOMEVAR
   RUN &TOBERUN

STATUS

This behavior is by design.

MORE INFORMATION

To demonstrate this behavior, create a batch file called A.BAT in the FoxPro directory. Then type the following in the command window:

   TOBERUN = "A.BAT" <Enter>
   RUN &TOBERUN <Enter>

This command will work as expected. Now, modify the variable assignment by typing the following:

   M.TOBERUN = "A.BAT" <Enter>
   RUN &M.TOBERUN <Enter>

MS-DOS returns the error message, "Bad command or file name," and the batch file fails to execute.

Additional reference words: FoxDos FoxWin 2.00 2.50 2.50a 2.50b 2.50c 2.60 2.60a memory variables m. prefix KBCategory: kbprg kbprb kbcode KBSubcategory: FxprgMacrosub

Last Reviewed: June 27, 1995