GetPrivateProfileString$()

Syntax

GetPrivateProfileString$(Section$, KeyName$, Filename$)

Remarks

Returns a setting in a settings file, a file that your macros can use to store and retrieve settings. For example, you can store the name of the active document when you quit Word so that it can be reopened automatically the next time you start Word. In Windows, a settings file is a text file such as WIN.INI. On the Macintosh, a settings file is a resource file such as Word Settings (6).

In Windows 95 and Windows NT, you can use GetPrivateProfileString$() to return a setting in the registry.

Argument

Explanation

Section$

The name of the section in the settings file that contains KeyName$. In Windows, the section name appears between brackets before the associated keys (do not include the brackets with Section$).

If you are using GetPrivateProfileString$() in Windows 95 or Windows NT to return a setting in the registry, Section$ should be the complete path to the key, including the root (for example, "HKEY_CURRENT_USER\Software\Microsoft\Word\7.0\Options").

KeyName$

The key whose setting you want to retrieve. In a Windows settings file, the key name is followed by an equal sign (=) and the setting.

If you are using GetPrivateProfileString$() in Windows 95 or Windows NT to return a value from the registry, KeyName$ should be the name of the value in the key specified by Section$ (for example, "MessageBeeps").

Filename$

The filename for the settings file. If a path is not specified, the Windows folder (Windows) or the Preferences folder (Macintosh) is assumed.

If you are using GetPrivateProfileString$() in Windows 95 or Windows NT to return a value from the registry, Filename$ must be an empty string ("").


If a specified section, key, or file does not exist, GetPrivateProfileString$() returns an empty string ("").

Example

This example sets the variable artdir$ to the path specified by the PICTURE-PATH key in the [Microsoft Word] section of WINWORD6.INI and, if the setting exists, changes the current folder accordingly. The last two instructions display the Insert Picture dialog box (Picture command, Insert menu). On the Macintosh, substitute Word Settings (6) for WINWORD6.INI. In Windows 95 and Windows NT, substitute the full path to the Options key for "Microsoft Word," and substitute an empty string ("") for WINWORD6.INI.


artdir$ = GetPrivateProfileString$("Microsoft Word", \
    "PICTURE-PATH", "WINWORD6.INI")
If artdir$ <> "" Then ChDir artdir$
Dim dlg As InsertPicture
x = Dialog(dlg)

For another example, see SetPrivateProfileString.

See Also

GetProfileString$(), SetPrivateProfileString, SetProfileString