Reply to comment

How to pass parameters to VFP EXE

Passing command-line parameters from Windows to VFP created EXE is different from passing parameters to VFP programs or functions in VFP application:

  • All parameters are passed to EXE as strings
  • Parameters should not be enclosed in single quotes because quotes will be treated as part of parameter
  • Parameters with spaces can be enclosed in double quotes
  • Parameters are separated by spaces not commas

In order to accept command-line parameters VFP application main program must begin with LPARAMETERS or PARAMETERS statement. A VFP form cannot be main in VFP application in this case because command-line parameters are not passed to the form's Init method.
It's not recommended to use a switch like parameters (that starts with '-' or '/') because they may conflict with VFP command-line switches. The complete list of VFP switches can be found in Command-Line Switches topic in VFP help. Martina Jindrù offers interesting alternative in Named Parameters.

Here's an example that shows how to pass parameters and accept them in VFP EXE.

This is sample code. Add error handling and adjust to your requirements as necessary.

* Shortcut's command-line box
"X:\Myapp\my.exe" 1234 "two items" 12/25/2002 .T.
 
* Main program of my.exe
LPARAMETERS tcPar1, tcPar2, tcPar3, tcPar4, tcPar5, tcPar6
 
* Parameter | Value       | Type | How to convert                  VFP 9.0
*-----------------------------------------------------------------------------------
* tcPar1      "1234"         C     INT(VAL(tcPar1))                CAST(tcPar1 AS I)
* tcPar2      "two items"    C      N/A                             N/A
* tcPar3      "12/25/2002"   C     EVALUATE("{" + tcPar3 + "}")    CAST(tcPar3 AS D)
* tcPar4      ".T."          C     EVALUATE(tcPar4)                CAST(tcPar4 AS L)
* tcPar5      .F.            L      N/A                             N/A
* tcPar6      .F.            L      N/A                             N/A

When less parameters passed to EXE than specified in the LPARAMETERS, the rest of parameters will have logical type and .F. value. The PCOUNT() function can be used to determine the number of passed parameters.

Reply

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <java>, <powershell>, <tsql>, <visualfoxpro>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.