Make the default value optional and return an error on a failed ReadPreference if no default is specified.
The preferences feature is very useful but being forced to provide a default creates extra work that is not necessary in many situations.
The help text states:
If the 'Keyword$' isn't found or the preference file haven't been opened correctly (file missing for example) the specified default value is returned.
Good programming practice requires that if the preferences file is missing then you create it and save the defaults accordingly. While I load all my preferences in one go, the requirement to specify a default would be especially onerous if ad hoc ReadPreference calls were being made throughout one's code; it would surely require the programmer to keep going back to find the correct default value.
nospam wrote:Good programming practice requires that if the preferences file is missing then you create it and save the defaults accordingly.
Um, yes... so if OpenPreferences() fails due to no prefs file existing, it returns 0 and you can just go ahead and create it (as you said). What's the problem, then? It's not like you need to start using default values at all, if it returns 0 when opening.
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
no prob if a pref exits or not if it IS a pref-file.
of course a pref-file with noncompliant content will spoil this. (this may be academic)
you could check in advance, wether the pref-file is "your" pref-file (no file or filled with "my" pref-stuff)
nospam wrote:Good programming practice requires that if the preferences file is missing then you create it and save the defaults accordingly.
Um, yes... so if OpenPreferences() fails due to no prefs file existing, it returns 0 and you can just go ahead and create it (as you said). What's the problem, then? It's not like you need to start using default values at all, if it returns 0 when opening.
I already said what the problem is. A default value is required, but the default value is not needed.
bobobo wrote:no prob if a pref exits or not if it IS a pref-file.
of course a pref-file with noncompliant content will spoil this. (this may be academic)
you could check in advance, wether the pref-file is "your" pref-file (no file or filled with "my" pref-stuff)
I don't know what you're talking about. Being forced to always specify a default value has nothing to do, per se, with whether or not a prefs file exists. It has nothing to do with non-compliant prefs files. It has nothing to do with checking in advance, and it has nothing to do with whether it's my pref file or someone else's.