Setting Configuration Options at Startup

In addition to making changes to the Visual FoxPro environment interactively, you can establish configuration settings when you first start the program. Doing so allows you to override default settings.

Using SET Commands

One way to establish configuration settings is to issue one or more SET commands when your application starts. For example, to configure your system to display a clock in the status bar when the application starts, you can issue this SET command:

SET CLOCK ON

At the exact point at which you issue the SET command, you can issue SET commands in the code for the Load or Init events of the form. It depends on your application. In general, you would issue SET commands from your application's main program file, which is the program or form that controls access to the rest of your application. For details about specifying a main file for an application, see Compiling an Application.

If your application begins by displaying a form, your application begins with a menu and you can add the SETUP commands by entering them in the menu's Setup option. For details see Adding Setup Code to a Menu System in Designing Menus and Toolbars.

Tip   An efficient way to manage SET commands for startup is to create a procedure that contains all the commands that you want to issue. You can then call the procedure from the appropriate point in your application. Keeping all the SETUP commands in a single procedure makes it easier to debug and maintain your configuration settings.

Using a Configuration File

In addition to setting the Visual FoxPro environment using the Options dialog box or SET commands, you can establish preferred settings and save them in one or more configuration files. A Visual FoxPro configuration file is a text file in which you can specify values for SET commands, set system variables, and execute commands or call functions. Visual FoxPro reads the configuration file when starting up, establishing the settings and executing the commands in the file. Settings made in the configuration file override default settings made in the Options dialog box (and stored in the Windows registry).

Using a configuration file provides several advantages. You can:

  • Override the default settings established in the Options dialog box.
  • Maintain several different configuration files, each with different settings, so that Visual FoxPro can load a configuration suitable to a particular user or project.
  • Make changes more easily than if you establish settings with the SET commands in the program initialization sequence.
  • Start a program or call a function automatically when Visual FoxPro starts.

Creating a Configuration File

To create a configuration file, use the Visual FoxPro editor (or any editor that can create text files) to create a text file in the directory where Visual FoxPro is installed. Earlier versions of Visual FoxPro created the file Config.fpw in the startup directory. Config.fpw became the default configuration file. You can create any program file and use it to establish default settings and behaviors by starting Visual FoxPro using that file either by double clicking the file or using a command line reference.

If you are creating a new configuration file, you can save it using any name you want. By convention, configuration files have the extension .fpw.

When you start Visual FoxPro you can use a default configuration file in the following locations (in order):

  • The current working directory.
  • The directory where Visual FoxPro is installed.
  • The directories listed in the DOS path.

If the default configuration file is not found in these locations, Visual FoxPro uses only the default settings established in the Options dialog box.

Note   For details about specifying an alternative to the default file name or location for the configuration file, see Specifying the Configuration File to Use.

Enter configuration settings using one of these methods:

  • Make settings with the SET command.
  • Set system variables.
  • Call programs or functions.
  • Include special terms used only in configuration files.

To enter SET commands in a configuration file

  • Enter SET commands without the SET keyword and with an equal sign.

    For example, to set a default path type, use this format:

    DEFAULT = HOME()+"\VFP"
    

    To add a clock to the status bar, use this command:

    CLOCK = ON
    

To enter a setting for a system variable, use the same syntax you would use in the Command window or in a program.

To set system variables in a configuration file

  • Enter the name of the system variable, an equal sign (=), and the value to set the variable to.

    For example, the following command sets the caption of the main Visual FoxPro window:

    _SCREEN.Caption = "My Application"
    

    The following command specifies an alternative spelling checking program:

    _SPELLCHK = "SPLLCHK.EXE"
    

You can also call functions or execute programs from within a configuration file by using the COMMAND command. For example, you can start an initialization program as part of the startup process.

To call functions or execute commands in a configuration file

  • Enter COMMAND, an equal sign (=), and the command to execute or function to call.

    For example, to include the Visual FoxPro version number in the caption of the main Visual FoxPro window, use this command:

    COMMAND =_SCREEN.Caption=;
    "Visual FoxPro " + SUBSTR(VERS(),25,3)
    

    The following command launches a specific application when Visual FoxPro starts:

    COMMAND = DO MYAPP.APP
    

You can also use special terms in a configuration file that do not correspond to SET value, system variables, or commands.

To use special terms in a configuration file

  • Enter the special term, an equal sign (=), and the setting.

    For example, to set the maximum number of variables available in Visual FoxPro, use this command:

    MVCOUNT = 2048
    

For a complete list of special terms for configuration files, see Special Terms for Configuration Files.

Starting Applications or Programs Automatically

You can insert commands into a configuration file that automatically launches programs when Visual FoxPro starts. You can use these commands either to start an entire application or to start just a program, such as one that initializes system variables.

To start applications from a configuration file

  • Assign the name of your application to the _STARTUP System Variable anywhere in the configuration file:

    _STARTUP = MYAPP.APP
    

    -or-

  • Use the COMMAND command, which must be the last line in your configuration file:

    COMMAND = DO MYAPP.APP
    

Specifying the Configuration File to Use

When Visual FoxPro starts, you can specify a configuration file or bypass all configuration files, allowing Visual FoxPro to use its default settings.

When Visual FoxPro loads a configuration file, the settings in that file take precedence over corresponding default settings made in the Options dialog box.

To specify a configuration file

  • In the command line that starts Visual FoxPro, specify the -C switch and the name of the configuration file that you want to use (including a path if necessary). Do not put a space between the switch and the file name.

    -or-

  • In Windows, double-click the name of the configuration file to use. Visual FoxPro will start using the configuration file you have selected.

If you want to avoid using any configuration file, including the default file Config.fpw, you can suppress all configuration files. This causes Visual FoxPro to use only the default settings established in the Options dialog box.

To suppress a configuration file

  • In the command line that starts Visual FoxPro, add the -C switch with nothing after it.

    For example, to avoid any configuration file found in the startup directory or the system path, use this command line:

    Vfp7.exe -C
    

See Also

Customizing the Visual FoxPro Environment | Using Command-Line Options When Starting Visual FoxPro | Compiling an Application | Adding Setup Code to a Menu System | Designing Menus and Toolbars | Specifying the Configuration File to Use | Special Terms for Configuration Files | _STARTUP System Variable