Result = OpenPreferences(Filename$ [, Flags])
Opens a previously existing preference file.


Filename$ The filename of the preference file.
Flags (optional) It can be a combination of the following values:
  #PB_Preference_NoSpace: no spaces will be put around the equal sign joining key and values.
                          It can be useful when dealing with external preferences files which doesn't
                          accept spaces around equal sign.
  #PB_Preference_GroupSeparator: add an empty line between the groups to ease readability of the file.

Return value

Nonzero if the file has been successfully opened, zero otherwise.


If the file wasn't found or can't be opened, it is still possible to use the read functions and it will return the specified default value. It is very useful to initialize in one step the program variables. The functions like ReadPreferenceString() can be used to read the preference values stored in the file.

To remove a key or a group, use RemovePreferenceKey() and RemovePreferenceGroup(). To create or change the current group, use PreferenceGroup().

It is possible to change existing values with WritePreferenceString() and similar functions.

Once all write operations are done, ClosePreferences() needs to be called to really write the preferences back to disk (if it has been modified inbetween).


  ; Open a preference file
  OpenPreferences(#PB_Compiler_Home +"Examples\Sources\Data\test.pref")
  ; Examine Groups
  ; For each group
  While NextPreferenceGroup()
    text$ = text$ + PreferenceGroupName() + #LF$ ; its name
    ; Examine keys for the current group  
    ; For each key  
    While  NextPreferenceKey()                      
      text$ = text$ + PreferenceKeyName() + " = " + PreferenceKeyValue() + #LF$ ; its name and its data
    text$ = text$ + #LF$

  ; Display all groups and all keys with datas
  MessageRequester("test.pref", text$)

  ; Close the preference file

See Also


Supported OS


<- NextPreferenceKey() - Preference Index - PreferenceComment() ->