Jump to content

_Filewritefromarray error


 Share

Recommended Posts

When i run the script, it will show me the array when it hits arraydisplay, but when i try to write the array into a txt file i get this error

C:\Program Files\AutoIt3\Include\File.au3 (279) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

If FileWrite($hFile, $a_Array[$x] & @CRLF) = 0 Then

If FileWrite($hFile, ^ ERROR

Dim $aINI = IniReadSection($Log, 'Name')
For $i = 1 To $aINI[0][0]
    For $j = 1 To $aINI[0][0]-$i
        If Int($aINI[$j+1][1]) > Int($aINI[$j][1]) Then
            Local $sTemp = $aINI[$j][1]
            $aINI[$j][1] = $aINI[$j+1][1]
            $aINI[$j+1][1] = $sTemp
            Local $sTemp1 = $aINI[$j][0]
            $aINI[$j][0] = $aINI[$j+1][0]
            $aINI[$j+1][0] = $sTemp1
        EndIf
    Next
Next
_ArrayDisplay($aINI)

_FileCreate(@ScriptDir&"\Output.txt")
_FileWriteFromArray(@ScriptDir&"\Output.txt", $aINI, 1)
MsgBox("","",@error)
Link to comment
Share on other sites

_Filewritefromarray() doesn't support multi-dimensional arrays. Heres two functions I use when reading and writing 2 dimensional arrays to file. Try using them.

Func _FileWriteFrom2dArray($sFilePath, ByRef $avArray)
    Local $sStr, $hFile, $iRow, $iCol
    For $iRow = 0 To (UBound($avArray, 1) - 1)
        For $iCol = 0 To UBound($avArray, 2) - 1
            $sStr &= $avArray[$iRow][$iCol] & '|'
        Next
        $sStr = StringTrimRight($sStr, 1)
        $sStr &= @CRLF
    Next
    $hFile = FileOpen($sFilePath, 2)
    FileWrite($hFile, $sStr)
    FileClose($hFile)
    Return
EndFunc   ;==>_Filewritefrom2dArray

Func _FileReadTo2dArray($sFilePath, ByRef $aArray)
    Local $hFile, $iRow, $iCol, $aLocal[1], $aStr
    _FileReadToArray($sFilePath, $aLocal)
    If UBound($aLocal) = 1 Then
    SetError(1)
    Return
    EndIf
    $aStr = StringSplit($aLocal[1], "|")
    ReDim $aArray[$aLocal[0]][$aStr[0]]
    For $iRow = 1 To $aLocal[0]
        $aStr = StringSplit($aLocal[$iRow], "|")
        For $iCol = 1 To UBound($aArray, 2)
            $aArray[$iRow - 1][$iCol - 1] = $aStr[$iCol]
        Next
    Next
    Return
EndFunc   ;==>_FileTo2dArray
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...