Code archives/File Utilities/IniLib
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
The library is very easy to use. Just open or create the file with the standard ReadFile() and WriteFile() functions and use the library to read or write it. Here's a short description of what each command does: IniGroup(IniHandle,Group$): Set the current group when reading INI files. ReadIniField$(IniHandle,Key$[,DefVal$]): Reads a field in the current group. You can store the result into a Int, Float or String variable, depending on the type of data that the Ini Field stores. WriteIniComment(IniHandle,Comment$): Writes a comment in the ini file. WriteIniGroup(IniHandle,Group$): Creates a new group in the ini file. WriteIniField(IniHandle,Key$,Value$): Creates a new field in th eini file. | |||||
;************************************************* ; INI Access BlitzBasic library ; Written by Javier San Juan Cervera -- Jedive ; www.softiberia.tk ;************************************************* Function IniGroup(IniHandle,Group$) SeekFile IniHandle,0 If Group$="" Then Return True While Not Eof(IniHandle) If Lower$(ReadLine$(IniHandle))="["+Lower$(Group$)+"]" Then Return True Wend Return False End Function ;************************************************* Function ReadIniField$(IniHandle,Key$,DefVal$="") While Chr$(char)<>"]" And FilePos(IniHandle)>0 SeekFile IniHandle,FilePos(IniHandle)-1 char=ReadByte(IniHandle) If Chr$(char)<>"]" Then SeekFile IniHandle,FilePos(IniHandle)-1 Wend ReadLine$(IniHandle) While Not Eof(IniHandle) lin$=Trim$(ReadLine$(IniHandle)) If Left$(lin$,1)="[" Then Return DefVal$ If Left$(lin$,1)<>"#" And Left$(lin$,1)<>"" Then If Lower$(Left$(lin$,Instr(lin$,"=",1)-1))=Lower$(Key$) Then Return Right$(lin$,Len(lin$)-Instr(lin$,"=",1)) Wend Return DefVal$ End Function ;************************************************* Function WriteIniComment(IniHandle,Comment$) WriteLine IniHandle,"#"+Comment$ End Function ;************************************************* Function WriteIniGroup(IniHandle,Group$) WriteLine IniHandle,"["+Group$+"]" End Function ;************************************************* Function WriteIniField(IniHandle,Key$,Value$) WriteLine IniHandle,Key$+"="+Value$ End Function ;************************************************* |
Comments
None.
Code Archives Forum