ProfileString

Description

Obtains the string value of a setting in the profile file for your application.

NoteFile format ProfileString can read either ANSI or Unicode files.

Syntax

ProfileString ( filename, section, key, default )

Argument

Description

filename

A string whose value is the name of the profile file. If you do not specify a full path, ProfileString uses the operating system’s standard file search order to find the file.

section

A string whose value is the name of a group of related values in the profile file. In the file, section names are in square brackets. Do not include the brackets in section. Section is not case sensitive.

key

A string specifying the setting name in section whose value you want. The setting name is followed by an equal sign in the file. Do not include the equal sign in key. Key is not case sensitive.

default

A string value that ProfileString will return if filename is not found, or if section or key does not exist in filename.

Returns

String, with a maximum length of 4096 characters. Returns the string from key within section within filename. If filename is not found, section is not found in filename, or key is not found in section, ProfileString returns default. If key does not have a value, ProfileString returns the empty string ("").

Usage

Use ProfileInt or ProfileString to get configuration settings from a profile file that you have designed for your application.

You can use SetProfileString to change values in the profile file to customize your application’s configuration during execution. Before you make changes, you can use ProfileInt and ProfileString to obtain the original settings so you can restore them when the user exits the application.

NoteWindows registry ProfileString can also be used to obtain configuration settings from the Windows system registry. For information on how to use the system registry, see the discussion of initialization files and the Windows registry in the Resource Guide.

Examples

Example 1

These examples use a file called PROFILE.INI, which contains the following lines. Quotes around string values in the INI file are optional:

[Employee]
Name=Smith

[Dept]
Name=Marketing

Example 2

This statement returns the string contained in keyword Name in section Employee in file C:\PROFILE.INI and returns None if there is an error. In the example, the return value is Smith:

ProfileString("C:\PROFILE.INI", "Employee", &
   "Name", "None")

Example 3

The following statements open w_marketing if the string in the keyword Name in section Department of file C:\PROFILE.INI is Marketing:

IF ProfileString("C:\PROFILE.INI", "Department", &
   "Name", "None") = "Marketing" THEN
   Open(w_marketing)
END IF

See also