reading_20and_20writing_20.ini_20data_20files
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
reading_20and_20writing_20.ini_20data_20files [2018/03/31 13:19] – external edit 127.0.0.1 | reading_20and_20writing_20.ini_20data_20files [2024/01/05 00:21] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 2: | Line 2: | ||
//by Richard Russell, May 2006//\\ \\ You may want your program to read configuration settings or user options on start up, to avoid the user having to enter them every time. One way of doing that is to use the // | //by Richard Russell, May 2006//\\ \\ You may want your program to read configuration settings or user options on start up, to avoid the user having to enter them every time. One way of doing that is to use the // | ||
+ | <code ini> | ||
[settings] | [settings] | ||
aspect=1 | aspect=1 | ||
Line 15: | Line 16: | ||
compressor=mp4v | compressor=mp4v | ||
quality=512 | quality=512 | ||
+ | </ | ||
The file consists of a number of sections (here they are **settings** and **codec**) and within each section are one or more lines in the format " | The file consists of a number of sections (here they are **settings** and **codec**) and within each section are one or more lines in the format " | ||
+ | <code bb4w> | ||
DEF FNgetinistring(file$, | DEF FNgetinistring(file$, | ||
LOCAL buf% | LOCAL buf% | ||
Line 21: | Line 24: | ||
SYS " | SYS " | ||
= $$buf% | = $$buf% | ||
+ | </ | ||
You would call that from your program in the following way, using the above file (called ARCQTM.INI) as an example:\\ \\ | You would call that from your program in the following way, using the above file (called ARCQTM.INI) as an example:\\ \\ | ||
+ | <code bb4w> | ||
aperture = VAL(FNgetinistring(@usr$+" | aperture = VAL(FNgetinistring(@usr$+" | ||
compressor$ = FNgetinistring(@usr$+" | compressor$ = FNgetinistring(@usr$+" | ||
+ | </ | ||
Here it is assumed that the file resides in the user's **Documents** folder. You should always specify a full path to the file.\\ \\ Arguably, a better place to store the file would be the user's **Application Data** folder, which you can do as follows: | Here it is assumed that the file resides in the user's **Documents** folder. You should always specify a full path to the file.\\ \\ Arguably, a better place to store the file would be the user's **Application Data** folder, which you can do as follows: | ||
+ | <code bb4w> | ||
appdata$ = FNspecialfolder(26) | appdata$ = FNspecialfolder(26) | ||
aperture = VAL(FNgetinistring(appdata$+" | aperture = VAL(FNgetinistring(appdata$+" | ||
compressor$ = FNgetinistring(appdata$+" | compressor$ = FNgetinistring(appdata$+" | ||
+ | </ | ||
The **FNspecialfolder** routine is listed in the main Help documentation [[http:// | The **FNspecialfolder** routine is listed in the main Help documentation [[http:// | ||
+ | <code bb4w> | ||
SYS " | SYS " | ||
+ | </ | ||
The value **default%** is returned in the case where the section or key does not already exist in the .INI file, such as when first running a program. There is no equivalent system call for writing of integers and the method below should be used.\\ \\ To write data to (and if necessary create) a .INI file you can use the following procedure: | The value **default%** is returned in the case where the section or key does not already exist in the .INI file, such as when first running a program. There is no equivalent system call for writing of integers and the method below should be used.\\ \\ To write data to (and if necessary create) a .INI file you can use the following procedure: | ||
+ | <code bb4w> | ||
DEF PROCputinistring(file$, | DEF PROCputinistring(file$, | ||
LOCAL res% | LOCAL res% | ||
Line 36: | Line 47: | ||
IF res% = 0 ERROR 100, " | IF res% = 0 ERROR 100, " | ||
ENDPROC | ENDPROC | ||
+ | </ | ||
You would call that from your program as follows:\\ \\ | You would call that from your program as follows:\\ \\ | ||
+ | <code bb4w> | ||
PROCputinistring(appdata$+" | PROCputinistring(appdata$+" | ||
PROCputinistring(appdata$+" | PROCputinistring(appdata$+" | ||
+ | </ |
reading_20and_20writing_20.ini_20data_20files.1522502376.txt.gz · Last modified: 2024/01/05 00:16 (external edit)