Author Topic: Use of a ini file to declare variables  (Read 3258 times)

0 Members and 1 Guest are viewing this topic.

Offline doppler

  • Forum Regular
  • Posts: 241
    • View Profile
Use of a ini file to declare variables
« 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.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Use of a ini file to declare variables
« Reply #1 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
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

FellippeHeitor

  • Guest
Re: Use of a ini file to declare variables
« Reply #2 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
Direct download: 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.  
« Last Edit: August 15, 2018, 12:14:57 pm by FellippeHeitor »

Offline doppler

  • Forum Regular
  • Posts: 241
    • View Profile
Re: Use of a ini file to declare variables
« Reply #3 on: August 15, 2018, 12:34:09 pm »
Good answers now I got somethings to look at.