QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: doppler on August 15, 2018, 11:38:33 am

Title: Use of a ini file to declare variables
Post by: doppler on August 15, 2018, 11:38:33 am
Is it possible to to use a INI file to declare variables.  Like:

[string]
a$="one"
b$="two"

[constant]
a=1
b=2
c=3

[float double]
a,b,c

It would make my life easier, so I don't have to recompile every time i want to change a string or constant variable.
I see this all the time in c++ and other high level languages.  Or is QB64 too dumb, <-- not my opinion.
Title: Re: Use of a ini file to declare variables
Post by: SMcNeill on August 15, 2018, 11:59:01 am
Feel free to use my config file library:  http://qb64.freeforums.net/thread/51/steves-config-file-system
Title: Re: Use of a ini file to declare variables
Post by: FellippeHeitor on August 15, 2018, 12:12:58 pm
Last I remember, Steve's couldn't handle identical key names across sections, so I offer mine as well.

Project page: https://github.com/FellippeHeitor/INI-Manager (https://github.com/FellippeHeitor/INI-Manager)
Direct download: https://github.com/FellippeHeitor/INI-Manager/archive/master.zip (https://github.com/FellippeHeitor/INI-Manager/archive/master.zip)

This way, in your program, you'll be able to read from the sample file above like this:

Code: QB64: [Select]
  1. a$ = ReadSetting("myFile.ini", "string", "a$")
  2. b$ = ReadSetting("myFile.ini", "string", "b$")
  3.  
  4. a = VAL(ReadSetting("myFile.ini", "constant", "a"))
  5. b = VAL(ReadSetting("myFile.ini", "constant", "b"))
  6. c = VAL(ReadSetting("myFile.ini", "constant", "c"))
  7.  
  8. a# = VAL(ReadSetting("myFile.ini", "float double", "a"))
  9. b# = VAL(ReadSetting("myFile.ini", "float double", "b"))
  10. c# = VAL(ReadSetting("myFile.ini", "float double", "c"))
  11.  
Title: Re: Use of a ini file to declare variables
Post by: doppler on August 15, 2018, 12:34:09 pm
Good answers now I got somethings to look at.