[Solved] Create settings conf file at beginning

Post

Posted
Rating:
#1 (In Topic #389)
Avatar
Regular
Philippe734 is in the usergroup ‘Regular’
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/

Code (gambas)

  1. Public Sub Form_Open()
  2.    WriteSettings
  3. Private Sub WriteSettings()
  4.     Settings["Stack"] = 55  
There is no error.
The settings conf file is only created when I close my app :

Code (gambas)

  1. Public Sub Form_Close()  
  2.   WriteSettings
I need to create the settings conf file when the first time running, please, how to do ?

 Linux & Android enthusiast - France
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Regular
stevedee is in the usergroup ‘Regular’

Philippe734 said

…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:-

Code (gambas)

  1. Public Sub Form_Open()
  2.  
  3.    If Not Exist( \{... / Application.Name & ".conf"}) Then
  4.      \{create ... / Application.Name & ".conf"}
  5.    Endif
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Guru
cogier is in the usergroup ‘Guru’
Have a look at the attached program that should help.
<IMG src="http://www.cogier.com/gambas/Philippe.png"> </IMG>

Attachment



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.
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Regular
stevedee is in the usergroup ‘Regular’

cogier said

…You can force the settings to save with Settings.Save.
Sorry guys, I completely missed that.
Online now: No Back to the top

Post

Posted
Rating:
#5
Avatar
Regular
Philippe734 is in the usergroup ‘Regular’

cogier said

You can force the settings to save with Settings.Save.
Perfect, thanks! But, it seems that we need to set value before save:

Code (gambas)

  1. Private Sub WriteSettings()
  2.   Settings["Topic"] = Value  
  3.   If Not Exist(... /myapp.conf) Then
  4.     Settings.Save
  5.   Endif  

 Linux & Android enthusiast - France
Online now: No Back to the top

Post

Posted
Rating:
#6
Avatar
Regular
Serban is in the usergroup ‘Regular’
 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)
Online now: No Back to the top
1 guest and 0 members have just viewed this.