GLBasic forum

Main forum => GLBasic - en => Topic started by: doimus on 2009-Aug-02

Title: Reading numbers from INI files
Post by: doimus on 2009-Aug-02
Is it possible to read numbers (float, integer, etc) from an .ini file?
So we could read number values for variables, for example.

INIGET$() returns a string - is there a reason there is no INIGET/INIGET% command?

And tying directly into the above question, is there a way to typecast string into integer? Sort of reverse FORMAT$().
Title: Re: Reading numbers from INI files
Post by: PeeJay on 2009-Aug-03
Look up OPENFILE in the help file - this will enable you to read whatever you like from any file you wish (including ini files). Personally, I use this in preference to INIGET$ / INIPUT as it allows much more flexibility.

However, if you want to convert a string to a numerical value, simply MID$ the numerical portion, then it will do a straight convert - ie
Code (glbasic) Select

a$="23"
a=a$
PRINT a,0,0

will work perfectly
Title: Re: Reading numbers from INI files
Post by: doimus on 2009-Aug-03
It was my error (as expected  ;/), I used INIGET$() with wrong parameters. It works perfectly now.  I really, REALLY like that we get the speed of C++ and almost Python/Ruby ease of use with variables in GLB!

I needed INI files for this. It's for a configuration file, that user can edit externally to change resolution parameters, etc.
When using OPENFILE I would get binary files only, right?
Title: Re: Reading numbers from INI files
Post by: Moru on 2009-Aug-03
You can do whatever sort of file you want but if it's just a user-editable file for parameters I would preffer the INI format since everything is already done for you and you don't have to do anything special, just read the values and use them :-)