Jump to content

Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded


Recommended Posts

Do some scripting with an array.

Now got this error message, don't know how to handle it.

Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded

Any ideas?

Code needed?

Link to comment
Share on other sites

Code needed?

Yes, or a short example..

...

You recive this error because your array dimension range was exceeded.

Here is an example of bad coding :

Local $Array[5]
;your array is $Array[0], $Array[1], $Array[2], $Array[3], $Array[4]

; If you want to assign a value to $Array[5] will generate error
$Array[5] = 0 ; error
Edited by PlayHD
Link to comment
Share on other sites

Look at ReDim and UBound in the help file.

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

Link to comment
Share on other sites

Bad coding, I'm your man. ;-)

There is always room for improvements.

Here the code of my script.

I want to open the xbmc export xml file with the movies stored in the database and compare them with the movie files on the hard disk, cause not all files have been detected by the xbmc scrapper. So I want to find the files on the hard disk which are not stored in the xml file.

#include 
#include 
#include 
#include 
#include 
#include 



$ScriptName = "XML Reader - Vergleich Filename"
$XMLFile = "D:\videodb.xml"
$OutputExcel = "D:\Liste.xls"
$InputFolder = "e:\"



; GUI Dialog zum Auswählen der videodb.xml
$XMLFile = FileOpenDialog("videodb.xml auswhälen...", @DesktopDir & "\", "Alle (*.*)", 1 + 2 )

; GUI Dialog zum Auswählen des Verzeichnisses mit den Filmen
$InputFolder = FileSelectFolder ("Filmverzeichnis auswählen...", "", 2)
;$InputFolder = $InputFolder & "\"

MsgBox(0, $ScriptName, "Videodb.xml: " & $XMLFile & @CRLF & "Verzeichnis: " & $InputFolder)


; Verzeichnis einlesen und Dateien in Array schreiben
$aArray = _RecFileListToArray($InputFolder, "*", 1, 1, 1, 2)

; Element löschen (Counter)
_ArrayDelete($aArray, 0)

; Array in eine XLS Datei schreiben
;_ArrayToXLS($aArray, $OutputExcel)




If FileExists($XMLFile) Then
$tmp = _XMLFileOpen($XMLFile)

If $tmp = "0" Then
MsgBox(16, $ScriptName, "Die Datei " & $XMLFile & " konnte nicht geöffnet werden")
Exit
EndIf

$counter = _XMLGetNodeCount("/videodb/movie")
;MsgBox(16, $ScriptName, $counter)

$titel = _XMLGetValue("/videodb/movie/title")
_ArrayDelete($titel, 0)

$originaltitel = _XMLGetValue("/videodb/movie/originaltitle")
_ArrayDelete($originaltitel, 0)

$dateiname = _XMLGetValue("/videodb/movie/filenameandpath")
_ArrayDelete($dateiname, 0)




; Array für die Spalten definieren
Local $xarray[$counter][4]

; Schleife um ein mehrdimensionales Array zu erstellen
For $i=0 To UBound($aArray) -1

$xarray[$i][0] = $titel[$i]
$xarray[$i][1] = $originaltitel[$i]
$xarray[$i][2] = $dateiname[$i]
$xarray[$i][3] = $aArray[$i]

Next

_ArrayDisplay($xarray)
; Array sortieren
_ArraySort($xarray)
;_ArrayDisplay($xarray)

; Array in eine XLS Datei schreiben
;_ArrayToXLS($xarray, $OutputExcel)



; Arrays vergleichen
$i = 0
While $i <= UBound($aArray) - 1
$matches = _ArrayFindAll($dateiname,$aArray[$i])
If UBound($matches) = 1 Then
_ArrayDelete($aArray,$i)
Else
$i += 1
EndIf
WEnd
_ArrayDisplay($aArray)


; Excel öffnen und ein Zeile einfügen und Zellen beschriften
;$oExcel = _ExcelBookOpen($OutputExcel, 1)
;_ExcelRowInsert($oExcel, 1, 1)
;_ExcelWriteCell($oExcel, "Filmtitel", "A1")
;_ExcelWriteCell($oExcel, "Originaltitel", "B1")
;_ExcelWriteCell($oExcel, "Auflösung", "C1")
;_ExcelWriteCell($oExcel, "Dauer", "D1")
;_ExcelBookSaveAs($oExcel, "tmp_"&$OutputExcel, "xls", "", 1)
; _ExcelBookClose($oExcel)



Else
MsgBox(16, $ScriptName, "Die Datei " & $XMLFile & " konnte nicht gefunden werden")

EndIf


Exit










; #FUNCTION# ====================================================================================================================
; Name...........: _ArrayToXLS
; Description ...: Places the elements of an 1D or 2D array into an Excel file (XLS).
; Syntax.........: _ArrayToXLS(Const ByRef $avArray, $sFileName[, $Transpose = False[, $iStartRow = 0[, $iEndRow = 0[, $iStartCol = 0[, $iEndCol = 0]]]]])
; Parameters ....: $avArray - Array to save
; $sFileName - Full path to XLS file
; $Transpose - [optional] At 2D array changes rows and columns
; $iStartRow - [optional] Zero based index (row) of array to start saving at
; $iEndRow - [optional] Zero based index (row) of array to stop saving at, if zero then last row is taken
; $iStartCol - [optional] Zero based index (column) of array to start saving at
; $iEndCol - [optional] Zero based index (column) of array to stop saving at, if zero then last column is taken
; Return values .: Success - 1
; Failure - 0, sets @error:
; |1 - $avArray is not an array
; |2 - $avArray is not 1D/2D array
; |3 - $iStartRow is greater than $iEndRow
; |4 - $iStartCol is greater than $iEndCol
; |5 - couldn't create XLS file
; Author ........: Zedna
; Modified.......:
; Remarks .......: Function supports 1D and 2D arrays. All array's data are converted to String datatype.
; This function doesn't depend on installed Microsoft Excel.
; Related .......: _ArrayToString, _ArrayToClip
; Link ..........;
; Example .......; Yes
; ===============================================================================================================================
Func _ArrayToXLS(Const ByRef $avArray, $FileName, $Transpose = False, $iStartRow = 0, $iEndRow = 0, $iStartCol = 0, $iEndCol = 0)
Local $nBytes

If Not IsArray($avArray) Then SetError(1, 0, 0)
$iDimension = UBound($avArray, 0)
If $iDimension > 2 Then SetError(2, 0, 0)

$iUBound1 = UBound($avArray, 1) - 1
If $iEndRow < 1 Or $iEndRow > $iUBound1 Then $iEndRow = $iUBound1
If $iStartRow < 0 Then $iStartRow = 0
If $iStartRow > $iEndRow Then Return SetError(3, 0, 0)

If $iDimension = 2 Then
$iUBound2 = UBound($avArray, 2) - 1
If $iEndCol < 1 Or $iEndCol > $iUBound2 Then $iEndCol = $iUBound2
If $iStartCol < 0 Then $iStartCol = 0
If $iStartCol > $iEndCol Then Return SetError(4, 0, 0)
EndIf

$hFile = _WinAPI_CreateFile($FileName, 1)
If @error Then Return SetError(5, 0, 0)

$str_bof = DllStructCreate('short;short;short;short;short;short')
DllStructSetData($str_bof, 1, 0x809)
DllStructSetData($str_bof, 2, 0x8)
DllStructSetData($str_bof, 3, 0x0)
DllStructSetData($str_bof, 4, 0x10)
DllStructSetData($str_bof, 5, 0x0)
DllStructSetData($str_bof, 6, 0x0)
_WinAPI_WriteFile($hFile, DLLStructGetPtr($str_bof), DllStructGetSize($str_bof), $nBytes)

Switch $iDimension
Case 1 ; 1D array
For $i = $iStartRow To $iEndRow ; 0 To $iUBound1
If $Transpose Then
__XLSWriteCell($hFile, 0, $i - $iStartRow, $avArray[$i])
Else
__XLSWriteCell($hFile, $i - $iStartRow, 0, $avArray[$i])
EndIf
Next

Case 2 ; 2D array
For $i = $iStartRow To $iEndRow ; 0 To $iUBound1
For $j = $iStartCol To $iEndCol ; 0 To $iUBound2
If $Transpose Then
__XLSWriteCell($hFile, $j - $iStartCol, $i - $iStartRow, $avArray[$i][$j])
Else
__XLSWriteCell($hFile, $i - $iStartRow, $j - $iStartCol, $avArray[$i][$j])
EndIf
Next
Next
EndSwitch

$str_eof = DllStructCreate('short;short')
DllStructSetData($str_eof, 1, 0x0A)
DllStructSetData($str_eof, 2, 0x0)
_WinAPI_WriteFile($hFile, DLLStructGetPtr($str_eof), DllStructGetSize($str_eof), $nBytes)

_WinAPI_CloseHandle($hFile)
Return 1
EndFunc ; ==> _ArrayToXLS

; internal helper function for _ArrayToXLS()
Func __XLSWriteCell($hFile, $Row, $Col, $Value)
Local $nBytes

$Value = String($Value)
$Len = StringLen($Value)

$str_cell = DllStructCreate('short;short;short;short;short;short')
DllStructSetData($str_cell, 1, 0x204)
DllStructSetData($str_cell, 2, 8 + $Len)
DllStructSetData($str_cell, 3, $Row)
DllStructSetData($str_cell, 4, $Col)
DllStructSetData($str_cell, 5, 0x0)
DllStructSetData($str_cell, 6, $Len)
_WinAPI_WriteFile($hFile, DLLStructGetPtr($str_cell), DllStructGetSize($str_cell), $nBytes)

$tBuffer = DLLStructCreate("byte[" & $Len & "]")
DLLStructSetData($tBuffer, 1, $Value)
_WinAPI_WriteFile($hFile, DLLStructGetPtr($tBuffer), $Len, $nBytes)
EndFunc ; ==> __XLSWriteCell
Link to comment
Share on other sites

If you run the code in ScITE4AutoIt3 it will display the error in the console. I say this because I don't have XBMC to test.

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

Link to comment
Share on other sites

The script works fine if I choose only a subdirectory with movies in it.

There are different subdirectories on the hard disk, if I choose the root with all subdirectories the script does not work and I get the error message.

When I choose a subdirectory it works fine.

It seems it depends on the number of movies found and the size/limit of the array.

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...