Page 1 of 1

[Solved] Create settings conf file at beginning

Posted: Tuesday 24th March 2020 3:31pm
by Philippe734
Hello,
When I run my app for the first time in IDE, the following code don't create the settings conf file in .config/gambas3/
Public Sub Form_Open()
   WriteSettings
End
Private Sub WriteSettings()
    Settings["Stack"] = 55  
End
There is no error.
The settings conf file is only created when I close my app :
Public Sub Form_Close()  
  WriteSettings
End
I need to create the settings conf file when the first time running, please, how to do ?

Re: Create settings conf file at beginning

Posted: Tuesday 24th March 2020 4:56pm
by stevedee
Philippe734 wrote: Tuesday 24th March 2020 3:31pm ...I need to create the settings conf file when the first time running, please, how to do ?
I don't think you can control the way the Setting feature generates the config file (i.e. it always waits until your program is closing to do this, even if you put "Settings["Stack"] = 55" anywhere other than the "Public Sub Form_Close()" event.

But if its really important to you, just check when your program starts whether there in a .conf file. If not create one, something like:-
Public Sub Form_Open()

   If Not Exist( {... / Application.Name & ".conf"}) Then
     {create ... / Application.Name & ".conf"}
   Endif
End

Re: Create settings conf file at beginning

Posted: Tuesday 24th March 2020 5:21pm
by cogier
Have a look at the attached program that should help.
Image
Philippe-0.0.4.tar.gz
(11.7 KiB) Downloaded 336 times

I don't think you can control the way the Setting feature generates the config file (i.e. it always waits until your program is closing to do this, even if you put "Settings["Stack"] = 55" anywhere other than the "Public Sub Form_Close()" event.
You can force the settings to save with Settings.Save.

Re: Create settings conf file at beginning

Posted: Tuesday 24th March 2020 5:40pm
by stevedee
cogier wrote: Tuesday 24th March 2020 5:21pm ...You can force the settings to save with Settings.Save.
Sorry guys, I completely missed that.

Re: Create settings conf file at beginning

Posted: Tuesday 24th March 2020 5:48pm
by Philippe734
cogier wrote: Tuesday 24th March 2020 5:21pmYou can force the settings to save with Settings.Save.
Perfect, thanks! But, it seems that we need to set value before save:
Private Sub WriteSettings()
  Settings["Topic"] = Value  
  If Not Exist(... /myapp.conf) Then
    Settings.Save
  Endif  
End

Re: [Solved] Create settings conf file at beginning

Posted: Saturday 28th March 2020 11:55am
by Serban
Are you surre it works?
I gave up using [gb.settings] for that very reason. Further more, it seems it has a weird bug related to a certain sequence of characters, that if used for sometime, triggers a "NULL" error. That points me to a memory leak that propagates somehow and extends over the app.
Namely...
I used [gb.settings] in a previous version to do exactly this: save settings. While the code worked flawlessly for 3 weeks, one day the "NULL Error" popped up and I had to spent many hours to fix the whole app.
I simply feel knocked down by that!
How the heck can a code that works and is untouched for more than 20 days to get scrambled? In a sudden?
It's unbelivable!
The word that triggered the "NULL" error was "Preferences". I can barely figure out what that means. It feels to me like being in the middle of nowhere...
Two questions:
1. Why did it work for THREE WEEKS day after day, after day, countless hours (sometimes over 15 hours...)??!
2. IF IT WORKED, then how come that it ceased working? SAME CODE? Untouched?!
While I can understand that my programming skills are way below fixing this kind of things, my understanding fades away when it comes to a thoroughly tested coode that one day, refuses to work.
There is an explanation, though. Quantum resonance. But that is far more complicated than I like.