Futurebasic/Language/Reference/put preferences

From Wikibooks, open books for an open world
Jump to navigation Jump to search

statement[edit | edit source]

Syntax[edit | edit source]

PUT PREFERENCES prefFilePath$, prefRecord

Revised[edit | edit source]

Description[edit | edit source]

This statement locates the named preferences file and writes the contents of the file from the indicated preferences record. If the file does not exist, it is created. This routine places the file in the preferences folder and works regardless of what system software is in use. The file may contain a folder in the form foldername:fileanme where a colon separates the folder name(s) from the file name.

In order to use any of the PREFERENCE commands you must include the proper header file using the following statement:

INCLUDE "Subs PrefsFile.Incl"

The following example shows how to manage a set of preferences using the new PREFERENCE commands. A Boolean value and a text string are saved in the preference file when the "Save Prefs" button is clicked. If you run the program a second time, you will see that modified prefs were properly stored and retrieved.

"Image Was Here"

<code><b>INCLUDE</b> 
<code><b>BEGIN GLOBALS</b></code>

<code><b>BEGIN RECORD</b> prefsRecord<b>DIM</b> prefChoice <b>AS BOOLEAN</b><b>DIM</b> prefText <b>AS STR255
END RECORD</b></code>

<code><b>DIM</b> gPref <b>AS</b> prefsRecord</code>

<code><b>END GLOBALS</b></code>

<code><b>LOCAL FN</b> readPreferences<br>
// set up defaults in case there is nothing to read 
// would be the case with the first run of the program)</code>

<code>gPref.prefChoice = _zTrue
gPref.prefText = "Text is saved with prefs"</code>

<code>// read the prefs on top of the defaults
<b>GET PREFERENCES</b> "My Pref File",gPref</code>

<code><b>END FN</b></code>

<code><b>LOCAL FN</b> savePreferences
gPref.prefChoice = (<b>BUTTON</b> (1) = _markedBtn)<br>gPref.prefText = <b>EDIT$</b>(1)
  <b>PUT PREFERENCES</b>gPref
<b>END FN</b></code>

<code><b>LOCAL<br>
DIM</b> r <b>AS RECT
LOCAL FN</b> setUp<br>
<b>SETRECT</b>(r,0,0,220,136)
<b>WINDOW</b> 1, "Preferences",@r
<b>SETRECT</b>(r,16,16,window(_width) - 16,32)
<b>BUTTON</b> 1,1, "Yes",@r,_radio
<b>OFFSETRECT</b>(r,0,24)
<b>BUTTON</b> 2,1, "No",@r,_radio</code>

<code><b>  OFFSETRECT</b>(r,0,24)
<b>EDIT FIELD</b> 1,"",@r
<b>OFFSETRECT</b>(r,0,24)
r.bottom = r.bottom + 8
<b>BUTTON</b> 3,1,"Save Prefs",@r</code>

<code><b>  IF</b> gPref.prefChoice <b>THEN BUTTON</b> 1,2 <b>ELSE BUTTON</b> 2,2
<b>EDIT$</b>(1) = gPref.prefText
<b>END FN</b></code>

<code><b>LOCAL
DIM</b> action,reference
<b>LOCAL FN</b> dodialog
action = <b>DIALOG</b>(0)
reference = <b>DIALOG</b>(action)
<b>LONG IF</b> action = _btnclick</code>

<code><b>SELECT</b> reference
<b>CASE</b> 1 //yes
<b>BUTTON</b> 1,2
<b>BUTTON</b> 2,1
<b>CASE</b> 2 //no
<b>BUTTON</b> 1,1
<b>BUTTON</b> 2,2
<b>CASE</b> 3 //save prefs
<b>FN</b> savePreferences
gFBquit = _zTrue
</code><code><b>END SELECT
</b>  <b>END IF
</b><b>END FN</b></code>

<code><b>ON DIALOG FN</b> doDialog
<b>FN</b> readPreferences
<b>FN</b> setUp</code>

<code><b>DO
</b>  <b>HANDLEEVENTS
</b><b>UNTIL</b> gFBquit</code>

See Also[edit | edit source]

GET PREFERENCES; KILL PREFERENCES; MENU PREFERENCES