Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Command Line Parameters

Status
Not open for further replies.

tkee

Programmer
Feb 6, 2004
55
0
6
US
Can I pass a parameter to a compiled Visual FoxPro executable? If so, how do I pass it and where do I need to put the parameters statement in my project?
 
You will need to set a PRG file as the main project file, then this is your entry point in the EXE.
And there goes your LPARAMETERS. The OS limits you to receive string values only, you only get the typical .F. value for non passed in parameters, all parameters up to PCOUNT() will be string type.

You don't get command line parameters like -C to specify a config.fpw or -L to specify a certain language resource runtime DLL. Those are handled by the runtime before your code is executed.

Besides, even without LPARAMETERS you could determine parameterization of the EXE via
Code:
Declare String GetCommandLine in win32api
? GetCommandLine()
Eg if doing so for your VFP IDE you get the EXE name itself. The string will always begin with the path and EXE file name and then continue with parameters, including the command-line options the runtime already consumed of course.

Bye, Olaf.

PS: Also see
Important to notice: EXE Parameters have to be separated by spaces and if you want a parameter to contain a space put it in double quotes, actually just the way EXE parameters work, but not the way you parameterize a VFP function with comma separated values and native types. There also are no by reference parameters to an EXE, so eg you can't call param="Hello, World" and then RUN YOUR.EXE @param and expect param to change after the exe finishes, actually I'd expect you'd get "@param" in the first parameter of YOUR.EXE, then, not even the param value "Hello, World".
 
Yes, this is easy. Just add an LPARAMETERS statement at the start of your main program. For details of the syntax of this statement, see the relevant Help topic.

Note that the values received will be local to the main program. If you need to use those values elsewhere, you will need to store them in a suitable variable or property, or pass them down the chain as parameters to lower-level functions or methods.

To pass the parameters, just add them to the command line in the normal way, that is, after the name of the executable. You can do that in a desktop shortcut, from a Run command, from a Dos session, or anywhere else.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thanks! Seems pretty simple and extremely useful.
 
You don't get command line parameters like -C to specify a config.fpw or -L to specify a certain language resource runtime DLL. Those are handled by the runtime before your code is executed.

Just to amplify this a bit, you should review the help file entry on startup switches.

You cannot pass, for example, /complete because VFP will look for a config file named "omplete". Avoid ALL of the startup switches VFP uses internally.
 
Yes, dan, at least avoid them for your own concerns, of course you can combine switches the runtime acts on and pass in further parameters arriving at your LPARAMETERS.

Bye, Olaf.
 
Some of those I use are as follows, they seem to be safe enough.

-P
-I
-S
-J
-F

You only really need one, to specify that the real parameters are in a file B-)

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are not good for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top