Reading numbers from INI files

Previous topic - Next topic

doimus

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$().

PeeJay

#1
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
www.peejays-remakes.co.uk
For games, remakes, and GL Basic Tutorials
Artificial Intelligence is no match for Natural Stupidity

doimus

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?

Moru

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