December 03, 2020, 08:50:20 PM

Author Topic: [bb] IniLib by JaviCervera [ 1+ years ago ]  (Read 528 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] IniLib by JaviCervera [ 1+ years ago ]
« on: June 29, 2017, 12:28:39 AM »
Title : IniLib
Author : JaviCervera
Posted : 1+ years ago

Description : 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.


Code :
Code: BlitzBasic
  1. ;*************************************************
  2. ; INI Access BlitzBasic library
  3. ; Written by Javier San Juan Cervera -- Jedive
  4. ; www.softiberia.tk
  5. ;*************************************************
  6.  
  7. Function IniGroup(IniHandle,Group$)
  8. SeekFile IniHandle,0
  9. If Group$="" Then Return True
  10. While Not Eof(IniHandle)
  11.         If Lower$(ReadLine$(IniHandle))="["+Lower$(Group$)+"]" Then Return True
  12. Wend
  13. Return False
  14. End Function
  15.  
  16. ;*************************************************
  17.  
  18. Function ReadIniField$(IniHandle,Key$,DefVal$="")
  19. While Chr$(char)<>"]" And FilePos(IniHandle)>0
  20.         SeekFile IniHandle,FilePos(IniHandle)-1
  21.         char=ReadByte(IniHandle)
  22.         If Chr$(char)<>"]" Then SeekFile IniHandle,FilePos(IniHandle)-1
  23. Wend
  24. ReadLine$(IniHandle)
  25. While Not Eof(IniHandle)
  26.         lin$=Trim$(ReadLine$(IniHandle))
  27.         If Left$(lin$,1)="[" Then Return DefVal$
  28.         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))
  29. Wend
  30. Return DefVal$
  31. End Function
  32.  
  33. ;*************************************************
  34.  
  35. Function WriteIniComment(IniHandle,Comment$)
  36. WriteLine IniHandle,"#"+Comment$
  37. End Function
  38.  
  39. ;*************************************************
  40.  
  41. Function WriteIniGroup(IniHandle,Group$)
  42. WriteLine IniHandle,"["+Group$+"]"
  43. End Function
  44.  
  45. ;*************************************************
  46.  
  47. Function WriteIniField(IniHandle,Key$,Value$)
  48. WriteLine IniHandle,Key$+"="+Value$
  49. End Function
  50.  
  51. ;*************************************************


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal