ProfileString

Description

Obtains the string value of a setting in the specified profile file.

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 returns if filename is not found, if section or key does not exist in filename, or if the value of key cannot be converted to an integer.


Return value

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 an error occurs, it returns the empty string ("").

Usage

Use ProfileInt and ProfileString to get configuration settings from a profile file you have designed for your application. ProfileInt and ProfileString can read files with ANSI or UTF16-LE encoding on Windows systems, and ANSI or UTF16-BE encoding on UNIX systems.

Using a DataWindow object in different environments

PowerBuilder

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

Web control

ProfileString always returns the value of default. It does not open a file on the user's machine; doing so would be a security violation.

Examples

This example uses the following section in the PROFILE.INI file:

[Employee]
Name="Smith"
[Dept]
Name="Marketing"

This expression returns the string for the keyword Name in section Employee in file C:\PROFILE.INI. It returns None if the section or keyword does not exist. In this case it returns Smith:

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

See also

ProfileInt

ProfileString in the section called “ProfileString” in PowerScript Reference

SetProfileString in the section called “SetProfileString” in PowerScript Reference