Code-Beispiel
Verbesserte INI-Laderoutine
Lizenz: | Erster Autor: | Letzte Bearbeitung: |
GPL | TiS | 08.02.2008 |
Hier ist eine verbesserte Version der von PMedia hochgeladenen INI-Laderoutine. Die Routine unterstützt jetzt auch Kommentare ("#"), und Schlüssel, die außerhalb einer Sektion stehen. Jetzt kann man auch Schlüssel ohne Namen angeben. Des weiteren habe ich ein paar Fehler ausgebessert und die Variablen aussagekräftiger benannt.
Declare Function tReadINI(strIniFile As String, strSection As String, strKey As String, strIgnore As String = "#") As String
Print tReadINI("test.ini", "", "")
Print tReadINI("test.ini", "krieger", "kraft")
Print tReadINI("test.ini", "krieger", "ausdauer")
Print tReadINI("test.ini", "katze", "pfoten")
Print tReadINI("test.ini", "tausendfuessler", "beine")
Print tReadINI("test.ini", "test", "test", "'")
Sleep
Function tReadINI(strIniFile As String, strSection As String, strKey As String, strIgnore As String = "#") As String
Dim intFile As Integer = FreeFile
Dim strBuffer As String
Dim isFound As Byte
If Open(strIniFile For Input As #intFile) <> 0 Then Return ""
If strSection = "" Then isFound = 1
Do Until isFound = 1 Or Eof(intFile)
Line Input #intFile, strBuffer
If Mid(strBuffer, 1, 1) = strIgnore Then Continue Do
If Trim(UCase(strBuffer)) = UCase("[" + strSection + "]") Then isFound = 1
Loop
If isFound = 0 Then
Close #intFile
Return ""
EndIf
isFound = 0
Do
Line Input #intFile, strBuffer
If Mid(strBuffer, 1, 1) = strIgnore Then Continue Do
If InStr(strBuffer, "=") And Left(strBuffer, InStr(strBuffer, "=") - 1) = strKey Then
isFound = 1
ElseIf Mid(strBuffer, 1, 1) = "[" Then
isFound = -1
EndIf
Loop Until isFound <> 0 Or Eof(intFile)
If isFound = -1 Or Eof(intFile) Then
Close #intFile
Return ""
End If
Close #intFile
Return Trim(Mid(strBuffer, InStr(strBuffer, "=") + 1, Len(strBuffer) - InStr(strBuffer, "=")))
End Function
Zusätzliche Informationen und Funktionen | |||||||
---|---|---|---|---|---|---|---|
|