'Routinen zu Ini-Dateien 'Die Funktionen und Subs verwenden als Eingabe- und Rckgabewerte Strings, bei Verwendung von Arrays=>Umwandeln.. 'Einfach bentigte Routine(n) rauskopieren und in eigenen Programmen verwenden.. 'Jetzt sind auch zwei Subs dabei fr Arrays '+------------------------------------------------------------------------------------------+ '| Header: Bestimmen der bergabeparameter' | '| AnzeigeCheck:|Il1 sind Alt-0124, Groes i, kleines L, Eins ᎙=ܱ| Const Author="IniMgmt.Bas v0.999 2007 by ytwinky, MD"' | '| (Tastenkombination: keine) | '| | '| Zweck : Lesen und Schreiben von Ini-Dateien | '+------------------------------------------------------------------------------------------+ Declare Function IniLoad(byVal DateiName As String) As String Declare Sub IniLoadM(byVal IniName As String, IniArray() As String) Declare Function IniRead(byVal IniFile As String, byVal Section As String, byVal IniKey As String, byVal default As String="") As String Declare Function IniReadLn(byVal IniFile As String, byVal Number As Integer) As String Declare Sub IniSave(byVal IniName As String, byVal Inhalt As String) Declare Sub IniSaveM(byVal IniName As String, IniArray() As String) Declare Sub IniWrite(byVal IniFile As String, byVal Section As String, byVal IniKey As String, byVal Wert As String="") Declare Sub IniWriteLn(byVal IniFile As String, byVal Number As Integer, byVal Value As String) Dim Feld(9) As String Print "Dies Programm kann mit FB0.183b kompiliert werden, die Routinen ggfs. anpassen.." Print "Eniki.."; GetKey End Function IniLoad(byVal IniName As String) As String Dim As String s, z, Qm=Chr(34), CrLf=Chr(13) &Chr(10) Dim As Integer i, EingabeDatei=FreeFile i=Open(IniName For Input As #EingabeDatei) If i Then s="Ooops, Datei " &IniName &" nicht gefunden(Fehler:#" &i &").." Print s; Sleep Else While Not Eof(EingabeDatei) Line Input #EingabeDatei, z If Left(z, 1)=Qm And Right(z, 1)=Qm Then z=Mid(z, 2, Len(z)-2) '\34 von Write entfernen s+=z &CrLf Wend Close #EingabeDatei End If Function=s End Function Sub IniLoadM(byVal IniName As String, IniArray() As String) Dim As String s, Qm=Chr(34) Dim As Integer IniFehler, i, EingabeDatei=FreeFile i=Open(IniName For Input As #EingabeDatei) If i Then Print "Ooops, Datei " &IniName &" nicht gefunden(Fehler:#" &i &").."; GetKey Else While Not Eof(EingabeDatei) Line Input #EingabeDatei, s If Left(s, 1)=Qm And Right(s, 1)=Qm Then s=Mid(s, 2, Len(s)-2) '\34 von Write entfernen IniArray(i)=s i+=1 Wend Close #EingabeDatei End If End Sub Function IniRead(byVal IniDatei As String, byVal Section As String, byVal IniKey As String, byVal default As String="") As String Dim As String Ini, s, Qm=Chr(34), CrLf=Chr(13) &Chr(10) Dim As Integer i, EingabeDatei=FreeFile i=Open(IniDatei For Input As #EingabeDatei) If i Then 'DateiFehler s="Ooops, Datei " &IniDatei &" nicht gefunden(#" &i &").." Print s; GetKey Else 'DateiLesen While Not Eof(EingabeDatei) Line Input #EingabeDatei, s If Left(s, 1)=Qm And Right(s, 1)=Qm Then s=Mid(s, 2, Len(s)-2) '\34 von Write entfernen Ini+=s &CrLf Wend Close #EingabeDatei s=default i=Instr(lcase(Ini), "[" &lcase(Section) &"]") If i Then i=Instr(i+Len(Section)+1, lcase(Ini), lcase(IniKey)) If i Then s=LTrim(Mid(Ini, i, Instr(i+Len(IniKey)+1, lcase(Ini), "=")-i)) End If End If End If Function=s End Function Function IniReadLn(byVal IniDatei As String, byVal Nummer As Integer) As String 'Mit 'echten' Nummern Dim As String s, Qm=Chr(34) Dim As Integer i, EingabeDatei=FreeFile i=Open(IniDatei For Input As #EingabeDatei) If i Then s="Ooops, Datei " &IniDatei &" nicht gefunden(#" &i &").." Print s; GetKey Else For i=1 To IIF(Nummer<1, 1, Nummer) Line Input #EingabeDatei, s If Left(s, 1)=Qm And Right(s, 1)=Qm Then s=Mid(s, 2, Len(s)-2) '\34 von Write entfernen Next Close #EingabeDatei End If Function=s End Function Sub IniSave(byVal IniName As String, byVal Inhalt As String) Dim As Integer Fehler, AusgabeDatei=FreeFile Fehler=Open(IniName For Output As #AusgabeDatei) If Fehler Then Print "Ooops, Datei " &IniName &" nicht offen(Fehler:#" &Fehler &").."; GetKey Else Write #AusgabeDatei, Inhalt Close #AusgabeDatei End If End Sub Sub IniSaveM(byVal IniName As String, IniArray() As String) Dim As Integer i, AusgabeDatei=FreeFile i=Open(IniName For Output As #AusgabeDatei) If i Then Print "Ooops, Datei " &IniName &" nicht offen(Fehler:#" &i &").."; GetKey Else For i=LBound(IniArray) To UBound(IniArray) Write #AusgabeDatei, IniArray(i) Next i 'IniZeile Close #AusgabeDatei End If End Sub Sub IniWrite(byVal IniDatei As String, byVal Section As String, byVal IniKey As String, byVal Wert As String="") Dim As String Ini, s Dim As Integer i Ini=IniLoad(IniDatei) i=Instr(lcase(Ini), "[" &lcase(Section) &"]") If i Then i=Instr(i+Len(Section)+1, lcase(Ini), lcase(IniKey)) If i Then s=LTrim(Mid(Ini, i, Instr(i+Len(IniKey)+1, lcase(Ini), "=")-i)) End If End If IniSave(IniDatei, Ini) End Sub Sub IniWriteLn(byVal IniDatei As String, byVal Nummer As Integer, byVal Wert As String) 'Mit 'echten' Nummern Dim As String Ini, s, Qm=Chr(34), CrLf=Chr(13) &Chr(10) Dim As Integer i, AusgabeDatei=FreeFile i=Open(IniDatei For Input As #AusgabeDatei) If i Then Print "Ooops, Datei " &IniDatei &" nicht offen(#" &i &").."; GetKey Else While Not Eof(AusgabeDatei) Line Input #AusgabeDatei, s If Left(s, 1)=Qm And Right(s, 1)=Qm Then s=Mid(s, 2, Len(s)-2) '\34 von Write entfernen i+=1 If i=Nummer Then s=Wert 'dieser Wert soll gendert werden.. Ini+=s &CrLf Wend Close #AusgabeDatei IniSave(IniDatei, Ini) End If End Sub