[Solved] Create settings conf file at beginning

Post Reply
User avatar
Philippe734
Posts: 15
Joined: Sunday 16th February 2020 7:37pm
Contact:

[Solved] Create settings conf file at beginning

Post by Philippe734 » Tuesday 24th March 2020 3:31pm

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 ?
Last edited by Philippe734 on Tuesday 24th March 2020 5:43pm, edited 1 time in total.
Linux & Android enthusiast - France

User avatar
stevedee
Posts: 203
Joined: Monday 20th March 2017 6:06pm

Re: Create settings conf file at beginning

Post by stevedee » Tuesday 24th March 2020 4:56pm

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

User avatar
cogier
Site Admin
Posts: 428
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Create settings conf file at beginning

Post by cogier » Tuesday 24th March 2020 5:21pm

Have a look at the attached program that should help.
Image
Philippe-0.0.4.tar.gz
(11.7 KiB) Downloaded 3 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.

User avatar
stevedee
Posts: 203
Joined: Monday 20th March 2017 6:06pm

Re: Create settings conf file at beginning

Post by stevedee » Tuesday 24th March 2020 5:40pm

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

User avatar
Philippe734
Posts: 15
Joined: Sunday 16th February 2020 7:37pm
Contact:

Re: Create settings conf file at beginning

Post by Philippe734 » Tuesday 24th March 2020 5:48pm

cogier wrote:
Tuesday 24th March 2020 5:21pm
You 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
Linux & Android enthusiast - France

User avatar
Serban
Posts: 32
Joined: Saturday 28th March 2020 8:17am
Location: Alexandria
Contact:

Re: [Solved] Create settings conf file at beginning

Post by Serban » Saturday 28th March 2020 11:55am

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.
The only thing necessary for the triumph of evil is for good men to do nothing.”― Edmund Burke;
It's easy to die for an idea. It is way harder to LIVE for your idea! (Me)

Post Reply