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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 * 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
Comments
Thanks
Thank you...
Thank You!
Thanks.
Thanks! Really useful piece
Excellent!!!
thanks
Thanks!
Very very fine ... thank you
VFP limitations on length of arguments?
http://social.msdn.microsoft.com/Forums/en-US/feeea559-4183-4fed-9081-3879e0d087de/command-line-parameters-length-limitation?forum=visualfoxprogeneral
Does anyone know if there's a fix for this?
command line parameters
Empty string parameters
How do you pass an empty string or a space as one of the parameters? Lets say your program takes 4 parameters and they're organized positionally, such that param1 means a certain thing, etc. In your program, it is acceptable for one or more of the parameters to be blank or a space or an empty string, and be followed by non-empty parameters. Eg. "X:\Myapp\my.exe" 1234 " " 12/25/2002 .T.
The problem is that VFP seems to consider the empty parameter not there and moves the remaining parameters to the left, so to speak, so what your program's main parameter statement actually sees is "X:\Myapp\my.exe" 1234 12/25/2002 .T.
Deactivate It
The fix:
Locate the main file in your project - it will be in bold font, and can be either a PRG or a Form (SCX).
Add following code to the main PRG (if a Form, add to the Init method):
LPARAMETERS p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16
Do not add any other code: your program will now accept up to 16 parameters but not do anything with them.
Why it works:
Unlike other languages which have an Arguments() type call to retrieve parameters, VFP expects you to add the LPARAMETERS statement to accept any parameters your code may be passed. Hence you are adding code to accept any passed parameters, but not adding any code to do anything with them.