Jump to content
Sign in to follow this  
allSystemsGo

File.au3 _FileWriteFromArray error

Recommended Posts

When writing an array to a file, I get this error in the console..

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

$s_Temp &= $s_Delim & $a_Array[$x][$y]

$s_Temp &= $s_Delim & ^ ERROR

->16:23:42 AutoIT3.exe ended.rc:1

>Exit code: 1 Time: 5.344

Here is the code.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <guilistview.au3>
#include <StaticConstants.au3>
#include <IE.au3>
#include <array.au3>
#include <File.au3>


$fIni = "c:\temp\zip.ini"

$count = 3
$zip = IniRead($fIni, "Zip", $count, "NotFound")
$url = "http://hosted.where2getit.com/truevalue/tv2.html?form=locator_search&addressline=42431&search=&geoip=1"
$oIE = _IECreate($url)
_IENavigate($oIE, $url)
_IEPropertySet($oIE, "silent", "true")
Local $oForm = _IEFormGetObjByName($oIE, "locator_search")
Local $oText = _IEFormElementGetObjByName($oForm, "inputaddress")
_IEFormElementSetValue($oText, $zip)
Send("{ENTER}")
_IETableReport($oIE)



Func _IETableReport($oIE)
Local $iIndex = 0

$colTables = _IETableGetCollection($oIE)

For $oTable In $colTables
;===== stolen from IE include _IETableWriteToArray, to find errors
Local $i_cols = 0, $tds, $i_col
Local $trs = $oTable.rows
For $tr In $trs
$tds = $tr.cells
$i_col = 0
For $td In $tds
$i_col = $i_col + $td.colSpan
Next
If $i_col > $i_cols Then $i_cols = $i_col
Next
Local $i_rows = $trs.length
If $i_cols = 0 Or $i_cols = 0 Then
MsgBox(1, "Failure to make good array from table", "Column count=" & $i_cols & "  Row count =" & $i_cols)
;======== end of , find array problems
Else
Global $aTableData = _IETableWriteToArray($oTable)
;_ArrayDisplay($aTableData, "Table #" & $iIndex)
$iIndex += 1

If $iIndex = 8 Then
_FileWriteFromArray("C:\temp\tv1.txt", $aTableData)
Else
Sleep(10)
EndIf

EndIf

Next

EndFunc   ;==>_IETableReport

Share this post


Link to post
Share on other sites

Make sure that $aTableData is an array before calling _FileWriteFromArray.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2019-08-19 - Version 1.4.13.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2019-07-24 - Version 1.3.6.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (NEW 2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (NEW 2019-10-09 - Version 0.9.0.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

What you should learn from this little problem is to check for errors after you called a function.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2019-08-19 - Version 1.4.13.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2019-07-24 - Version 1.3.6.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (NEW 2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (NEW 2019-10-09 - Version 0.9.0.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I have changed the code a bit...still trying out a few different ways to get my results. When I use _FileWriteFromArray, the file is created...but not with the whole array. The file should contain a 40 column array, but is only generates the first column.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <guilistview.au3>
#include <StaticConstants.au3>
#include <IE.au3>
#include <array.au3>
#include <File.au3>
Global $fIni,$zip, $url, $oIE
$fIni = "c:\temp\zip.ini"
$count = 3062
;~ $zip = IniRead($fIni, "Zip", $count, "NotFound")
$url = "http://hosted.where2getit.com/truevalue/printlocator_tv2.html?form=locator_search&addressline=90210&search=&like=0.9760303909649637"


;While 1
navIE()
;~          $zip = IniRead($fIni, "Zip", $count, "NotFound")
;Wend
If $count= 43627 Then Exit




Func navIE()
$oIE = _IECreate($url)
_IENavigate($oIE, $url)
WinKill("Print")
WinKill("Print")
_IEPropertySet($oIE, "silent", "false")


;~ Local $oForm = _IEFormGetObjByName($oIE, "locator_search")
;~ Local $oText = _IEFormElementGetObjByName($oForm, "inputaddress")
;~ _IEFormElementSetValue($oText, $zip)
;~ MsgBox(1,"",$zip)
;~ Send("{ENTER}")

_IETableReport($oIE)
 $count= $count + 1
;~ MsgBox(1,"",$count)
;~ $filename= "tv"&$zip&".txt"
;~ $sHtml = _IETableGetCollection($oIE)
;~ $file = FileOpen($filename, 2)
;~ FileWrite($file, $sHTML)
;~ FileClose($file)

EndFunc





Func _IETableReport($oIE)
Local $iIndex = 0

$colTables = _IETableGetCollection($oIE)

For $oTable In $colTables


Local $i_cols = 0, $tds, $i_col
Local $trs = $oTable.rows
For $tr In $trs
$tds = $tr.cells
$i_col = 0
For $td In $tds
$i_col = $i_col + $td.colSpan
Next
If $i_col > $i_cols Then $i_cols = $i_col
Next
Local $i_rows = $trs.length
If $i_cols = 0 Or $i_cols = 0 Then
MsgBox(1, "Failure to make good array from table", "Column count=" & $i_cols & "  Row count =" & $i_cols)
;======== end of , find array problems
Else
Global $aTableData = _IETableWriteToArray($oTable)
If $iIndex = 6 Then
;~  _ArrayDisplay($aTableData, "Table #" & $iIndex)
_FileWriteFromArray("C:\temp\tv"&$count&".txt", $aTableData)
Else
Sleep(10)
EndIf

EndIf
$iIndex += 1
Next

EndFunc   ;==>_IETableReport

Edited the code a bit, so you guys should be able to run it..

Share this post


Link to post
Share on other sites

Before _FileWriteFromArray insert a _ArrayDisplay to check the content of the array. Does it contain all 40 columns?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2019-08-19 - Version 1.4.13.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2019-07-24 - Version 1.3.6.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (NEW 2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (NEW 2019-10-09 - Version 0.9.0.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

It's because the function is bugged, try this update...

; #FUNCTION# ====================================================================================================================
; Name ..........: _FileWriteFromArray
; Description ...: Writes an array to a specified file.
; Syntax ........: _FileWriteFromArray($sFilePath, $aArray[, $iBase = 0[, $iUBound = 0[, $sDelimeter = "|"]]])
; Parameters ....: $sFilePath - Path of the file to write to, or a file handle returned by FileOpen().
;                  $aArray - [in/out and const] The array to be written to the file.
;                  $iBase - [optional] Start array index to read, normally set to 0 or 1. Default is 0.
;                  $iUBound - [optional] Set to the last record you want to write to the File. Default is 0 (whole array.)
;                  $sDelimeter - [optional] Delimiter character(s) for 2-dimension arrays. Default is "|".
; Return values .: Success - Returns a 1
;                  Failure - Returns a 0
;                  @error  - 0 = No error.
;                  |1 = Error opening specified file
;                  |2 = Input is not an Array
;                  |3 = Error writing to file
;                  |4 = Array dimensions > 2
;                  |5 = Start index is greater than the $iUbound parameter
; Author ........: Jos van der Zande <jdeb at autoitscript dot com>
; Modified.......: Updated for file handles by PsaltyDS, @error = 4 msg and 2-dimension capability added by Spiff59 and fixed by guinness.
; Remarks .......: If a string path is provided, the file is overwritten and closed.
;                  To use other write modes, like append or Unicode formats, open the file with FileOpen() first and pass the file handle instead.
;                  If a file handle is passed, the file will still be open after writing.
; Related .......: _FileReadToArray
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _FileWriteFromArray($sFilePath, Const ByRef $aArray, $iBase = Default, $iUBound = Default, $sDelimeter = "|")
    ; Check if we have a valid array as input
    If Not IsArray($aArray) Then Return SetError(2, 0, 0)

    ; Check the number of dimensions
    Local $iDims = UBound($aArray, 0)
    If $iDims > 2 Then Return SetError(4, 0, 0)

    ; Determine last entry of the array
    Local $iLast = UBound($aArray) - 1
    If $iUBound = Default Or $iUBound > $iLast Then $iUBound = $iLast
    If $iBase < 0 Or $iBase = Default Then $iBase = 0
    If $iBase > $iUBound Then Return SetError(5, 0, 0)
    If $sDelimeter = Default Then $sDelimeter = "|"

    ; Open output file for overwrite by default, or use input file handle if passed
    Local $hFileOpen = 0
    If IsString($sFilePath) Then
        $hFileOpen = FileOpen($sFilePath, $FO_OVERWRITE)
    Else
        $hFileOpen = $sFilePath
    EndIf
    If $hFileOpen = -1 Then Return SetError(1, 0, 0)

    ; Write array data to file
    Local $iError = 0
    Switch $iDims
        Case 1
            For $i = $iBase To $iUBound
                If FileWrite($hFileOpen, $aArray[$i] & @CRLF) = 0 Then
                    $iError = 3
                    ExitLoop
                EndIf
            Next
        Case 2
            Local $sTemp
            Local $iCols = UBound($aArray, 2)
            For $i = $iBase To $iUBound
                $sTemp = $aArray[$i][0]
                For $j = 1 To $iCols - 1
                    $sTemp &= $sDelimeter & $aArray[$i][$j]
                Next
                If FileWrite($hFileOpen, $sTemp & @CRLF) = 0 Then
                    $iError = 3
                    ExitLoop
                EndIf
            Next
    EndSwitch

    ; Close file only if specified by a string path
    If IsString($sFilePath) Then FileClose($hFileOpen)

    ; Return results
    If $iError Then Return SetError($iError, 0, 0)
    Return 1
EndFunc   ;==>_FileWriteFromArray

It's in the beta version of AutoIt which is floating around the Forum.


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites

You're welcome.


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
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
Sign in to follow this  

×
×
  • Create New...