Hallo alle beisammen.
Ich habe eine neue Iniread-Funktion geschrieben. Hintergrund ist die Begrenzung auf ~33.000 chars. Allerdings kommen noch einige Fehler beim Ausführen mit F5. Vor allem wegen "Return".
Hier die Funktion mit Beispielini im Anhang:
Spoiler anzeigen
#cs ----------------------------------------------------------------------------
AutoIt Version: 3.3.6.0
Author: Aquaplant
Script Function:
_Iniread($spath[, $sSection[, $sKey]])
#ce ----------------------------------------------------------------------------
#Include <String.au3>
$AAA = _IniRead(@ScriptDir & "\Test.txt")
If @error Then
MsgBox(0, "", @error)
EndIf
For $i = 1 To $AAA[0]
MsgBox(0, $AAA[0], $AAA[$i]
Next
Func _IniRead($sPath, $sSection = "", $sKey = "")
Global $sSectionname[999]
Local $sArray = ""
If FileExists($sPath) = 0 Then
SetError(1, 1, "Requested file does not exist")
Else
If $sSection = "" And $sKey = "" Then
$oHandle = FileOpen($sPath)
$i = 0
$a = 0
While 1
$i += 1
$sLine = FileReadLine($oHandle, $i)
If @error Then
If FileGetSize($sPath) <= 1 Then
SetError(2, 2, "No contents in the file")
EndIf
$sSectionname[0] = $a
FileClose($oHandle)
ExitLoop
EndIf
If StringLeft($sLine, 1) = "[" Then
$sArray = ""
$a += 1
$aLine = StringSplit($sLine, "]")
For $j = 1 To $aLine[0] - 1
$sArray &= $aLine[$j] & "]"
Next
$sArray = StringTrimRight($sArray, 1)
$sArray = StringTrimLeft($sArray, 1)
$sSectionname[$a] = $sArray
EndIf
WEnd
Return $sSectionname
EndIf
If $sSection <> "" And $sKey = "" Then
Global $aKV[999][999]
$i = 0
$j = 0
While 1
$i += 1
$sLine = FileReadLine($sPath, $i)
If @error Then
SetError(3, 3, "Section does not exist")
EndIf
If StringLeft($sLine, StringLen($sSection) + 2) = "[" & $sSection & "]" Then
While 1
$i += 1
$j += 1
$sLine = FileReadLine($sPath, $i)
If StringLeft($sLine, 1) = "[" Or @error Then
$aKV[0][0] = $j
ExitLoop 2
Else
$sString = ""
$aString = StringSplit($sLine, "=")
$aKV[$j][0] = $aString[1]
For $k = 2 To $aString[0]
If $aString[$k] = "" Then
$aString[$k] = "="
EndIf
$sString &= $aString[$k] & "="
Next
$sString = StringTrimRight($sString, 1)
$aKV[$j][1] = $sString
EndIf
WEnd
EndIf
WEnd
Return $aKV
EndIf
If $sSection <> "" And $sKey <> "" Then
$sFile = FileRead($sPath)
$aA = _StringBetween($sFile, $sKey & "=", @CRLF)
If IsArray($aA) = 0 Then
$aA = _StringBetween($sFile, $sKey, @CR)
EndIf
$sValue = $aA[0]
Return $sValue
EndIf
EndIf
EndFunc
Fehlertext:
Spoiler anzeigen
C:\Users\Work\Desktop\_IniRead.au3(16,29) : ERROR: syntax error
MsgBox(0, $AAA[0], $AAA[$i]
~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Users\Work\Desktop\_IniRead.au3(20,33) : WARNING: $sSection: possibly used before declaration.
Func _IniRead($sPath, $sSection =
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Users\Work\Desktop\_IniRead.au3(20,45) : WARNING: $sKey: possibly used before declaration.
Func _IniRead($sPath, $sSection = "", $sKey =
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Users\Work\Desktop\_IniRead.au3(23,22) : WARNING: $sPath: possibly used before declaration.
If FileExists($sPath)
~~~~~~~~~~~~~~~~~~~~^
C:\Users\Work\Desktop\_IniRead.au3(53,24) : ERROR: 'Return' not allowed from global scope.
Return $sSectionname
~~~~~~~~~~~~~~~~~~~~^
C:\Users\Work\Desktop\_IniRead.au3(89,15) : ERROR: 'Return' not allowed from global scope.
Return $aKV
~~~~~~~~~~~^
C:\Users\Work\Desktop\_IniRead.au3(98,18) : ERROR: 'Return' not allowed from global scope.
Return $sValue
~~~~~~~~~~~~~~^
C:\Users\Work\Desktop\_IniRead.au3(101,1) : ERROR: missing Next.
EndFunc
^
C:\Users\Work\Desktop\_IniRead.au3(15,12) : REF: missing Next.
For $i = 1 To
~~~~~~~~~~~^
C:\Users\Work\Desktop\_IniRead.au3(101,1) : ERROR: syntax error
EndFunc
^
C:\Users\Work\Desktop\_IniRead.au3(20,33) : ERROR: $sSection: undeclared global variable.
Func _IniRead($sPath, $sSection =
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Users\Work\Desktop\_IniRead.au3(11,41) : ERROR: _IniRead(): undefined function.
$AAA = _IniRead(@ScriptDir & "\Test.txt")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Users\Work\Desktop\_IniRead.au3 - 8 error(s), 3 warning(s)