Help with setting Preferences, please

Hi

I am using a PreferencesModule that I recently found online here:

link text

I have played around with it, and can store my preferences, change them in the Preference Window and quit the app and when I restart it, the changes are recorded.

Below is my current code. I have played around with it and changed it so many times, I can hardly remember what the original code looked like. Luckily I saved a version of my project elsewhere on my disk that I can go back to where I knew it worked. The code I have now (in the App Load Event):

[code] // Initialize the preferences by telling it the name of your app.
// Preferences will be stored in the SpecialFolder.ApplicationData
// in a folder with the app name in a file ending in “.pref”.
// So the below example would have preferences saved in:
// ApplicationData/PreferencesExample/PreferencesExample.pref

PreferencesModule.Initialize(“RainGauge”)

Rain_db = RainDatabase.SetupNewDatabase
If Rain_db <> Nil Then
RainGauge.fromDatabase = True
// Now you can load the preferences

If Not Preferences.Load Then
  // Set default values for preferences so that they
  // do not cause a PreferencesNotFoundException when accessed.
  Preferences.meaSys = "mm"
  Preferences.GaugeName = "My Rain Gauge"
End If

nameOfTitle = Preferences.GaugeName  // in this instance nameOfTitle is a property in the App class
RainGauge.Show

Else
Quit
End If
[/code]

Here is my problem, it doesn’t matter where I store the property values of the two things I am storing in the app (In the App, in the window which is using them, or in a module. It seems that if I put a breakpoint in the App load event I can see that the property is set (wherever I stored it), but if I put a breakpoint in the window (RainGauge.Show), the property is lost.

I am sure that my problem must be something to do with scope, but I have tried different permutations of where I store things for about seven or eight hours now. Perhaps someone could help me see the error of my ways?

I think this module does not work right

when I use

Preferences.Set("MainWindowLeft") = Window1.Left Preferences.Set("MainWindowTop") = Window1.Top

whatever the window position is, it stores always

“MainWindowLeft”:10,
“MainWindowTop”:50

Thanks Alex.

Since posting my request, I have just reached my limit with this Module. I am going through the two Webinars about the Text Editor. At least they have a Preference Window and separate Text Editing Windows. The example I followed before only had a Preferences window, and all you actual saw was the different values being stored to the pref file, and then retrieved. As I said above, I managed to see that work. It was just when I wanted to get those values into my main window (my app only has one window) that I struck problems. So this Webinar I am going to watch at least is similar to what I am trying to do.

it works when I write the code in Open and Close of the Window, in the example the code is in App.Open and App.Close

Thanks Axel

It’s another day here, so I will give it another try by putting the code in the one and only window of the app. I must say that I would like to use that PreferenceModule as it is a demonstration of OOP, which I am trying to wrap my head around.

Thanks for your trying things out and your feedback.

i can’t save preferences, the method save doesn’t work

OSX Win Linux ?

Window1.Open

PrefModule.Initialize(app.ExecutableFile.Name) If Not Preferences.Load Then return End If LoadPrefs

Window1.Close

SavePrefs If Not Preferences.Save Then return End If Quit

This is an old thread, but it didn’t end with any kind of resolution – which really frustrated me when I couldn’t get the Save part of PreferencesModule (PM) to work, either.

I finally discovered the reason for my problem – PM didn’t want me to add a Text item as the value. For example:

dim camps as Text = "" // blah blah blah, put some text stuff into the camps variable... Preferences.Set("Campaigns") = camps

That would blow up inside the PM.Save method.

But as soon as I changed the dim:

dim camps as String = ""

…then everything worked as it should.

Since PM is saving the values as a Variant, I wouldn’t think that change should do anything, but that’s the way I got it to work for my project.

Jay