J_Y_C Posted October 19, 2006 Share Posted October 19, 2006 I have a script that parses out file names, and then dumps it into an excel sheet. But, I keep getting this error: C:\Program Files\AutoIt3\Include\Indexer.au3 (25) : ==> Array variable subscript badly formatted.: Dim $newIndex[$arraySize][6] Dim $newIndex[^ ERROR I don't really understand the error, everything looks fine to me. I have read around, but have yet to see a specifc explanation of this error. I've marked the spot where the $newIndex is Dim'd. Here is the code: expandcollapse popup#include <ExcelCom.au3> #include <Process.au3> #include <GuiConstants.au3> #region --- GuiBuilder code Start --- ; Script generated by AutoBuilder 0.6 Prototype GuiCreate("MyGUI", 176, 166,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $Label_1 = GuiCtrlCreateLabel("Indexer", 10, 10, 70, 20) $List_2 = GuiCtrlCreateList("process", 10, 50, 160, 110) ;;;;;;;;;;;;;;;;;;;;;;;;;;MAIN SECTION;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; GuiSetState() While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case Else Opt("GUIOnEventMode", 1) _buildIndex() $arraySize = @extended ;;;;;;;;;;;;;;;;;;;;;;;;;THIS IS WHERE THE ERROR IN QUESTION IS HAPPENING;;;;;;;;;;;;;;;;;;; Dim $newIndex[$arraySize][6] $newIndex = _buildIndex() $name = @MON & "-" & @MDAY & "-" & @YEAR & "-CDG_Library" _createXLIndex($newIndex, "X:\", $name) EndSelect WEnd Exit ;;;;;;;;;;;;;;;;;;;;;;;;;;MAIN SECTION;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; #endregion --- GuiBuilder generated code End --- Func _buildIndex() ;builds the file index, parses the names, and then returns an array with the library ;@extended = size of returned array $numTitles = 0;total number of titles $alTotal = 0 $mzTotal = 0 GUICtrlSetData($List_2,"building index") FileChangeDir("X:\") _RunDos("dir /s /b *.bin > a-l.txt") FileChangeDir("Y:\") _RunDos("dir /s /b *.bin > m-z.txt") $alIndex = FileOpen("x:\a-l.txt",0) $mzIndex = FileOpen("Y:\m-z.txt",0) GUICtrlSetData($List_2,"counting lines") $complete = false $fileLine = 1 While $complete = false ;count the files from a-l index $currLine = FileReadLine($alIndex,$fileLine) $currLen=StringLen($currLine) If $currLen = 0 Then $complete = True ElseIf StringInStr($currLine,".bin") Then $numTitles +=1 $alTotal +=1 EndIf $fileLine +=1 WEnd ;count the files from the m-z index $complete = false $fileLine = 1 While $complete = false ;count the files from a-l index $currLine = FileReadLine($mzIndex,$fileLine) $currLen=StringLen($currLine) If $currLen = 0 Then $complete = True ElseIf StringInStr($currLine,".bin") Then $numTitles +=1 $alTotal +=1 EndIf $fileLine +=1 WEnd GUICtrlSetData($List_2,"creating arrays") ;size an array to be of the size of the total number of files Dim $Library[$numTitles][6];entire library Dim $tmpArray[6];temporary storage from the parser ;re-read each index into a string GUICtrlSetData($List_2,"parsing lines") $complete = false While $complete = false ;parse the files from a-l index for $i = 0 to ($alTotal-1) $currLine = FileReadLine($alIndex,$i+1) $tmpArray = _stringParse($currLine) For $j = 0 to 5 $Library[$i][$j]=$tmpArray[$j] GUICtrlSetData($List_2,$Library[$i][$j]) Next Next ;parse the files from m-z index for $i = $alTotal to ($numTitles-1) $currLine = FileReadLine($mzIndex,$i+1) $tmpArray = _stringParse($currLine) For $j = 0 to 5 $Library[$i][$j]=$tmpArray[$j] GUICtrlSetData($List_2,$Library[$i][$j]) Next Next $complete = True WEnd FileClose($alIndex) FileClose($mzIndex) Return $Library SetExtended($numTitles) ;return the complete array value EndFunc Func _createXLIndex(ByRef $Library, $path, $fileName) ;takes in a 2 dimensional array, a path, and a file name and creates an XL sheet containing a song index ;$path should have the trailing \ ex C:\temp\ $s_FilePath = $path & $fileName _XLCreateBlank($s_FilePath) $rows = UBound($Library,1) For $i = 0 to ($rows-1) _XLWrite($s_FilePath,1,"A",$i+1,$Library[$i][0],0,0) _XLWrite($s_FilePath,1,"B",$i+1,$Library[$i][1],0,0) _XLWrite($s_FilePath,1,"C",$i+1,$Library[$i][2],0,0) _XLWrite($s_FilePath,1,"D",$i+1,$Library[$i][3],0,0) _XLWrite($s_FilePath,1,"E",$i+1,$Library[$i][4],0,0) _XLWrite($s_FilePath,1,"F",$i+1,$Library[$i][5],0,0) Next EndFunc Func _stringParse(ByRef $FN) dim $parsedString[6] ;takes in a path and filename, returns a 6 element array of the file data $txtTmp=StringStripWS($FN,3) $currLine=$txtTmp ;for each file, you should have 6 elements, ;path, $parsedString[0]=StringLeft($currLine,5) $txtTmp=StringReplace($parsedString[0],"_"," ") $parsedString[0]=$txtTmp $txtTmp=StringStripWS($parsedString[0],3) $parsedString[0]=$txtTmp ;filename, $parsedString[1]=StringRight($currLine, (StringLen($currLine)-5)) $txtTmp=StringReplace($parsedString[1],"_"," ") $parsedString[1]=$txtTmp $txtTmp=StringStripWS($parsedString[1],3) $parsedString[1]=$txtTmp ;Title, $parsedString[2]=StringMid($currLine,6,(StringInStr($currLine,"-")-5)) $txtTmp=StringReplace($parsedString[2],"_"," ") $parsedString[2]=$txtTmp $txtTmp=StringStripWS($parsedString[2],3) $parsedString[2]=$txtTmp ;Artist, $parsedString[3]=StringMid($currLine,StringInStr($currLine,"-",0,1)+1,(StringInStr($currLine,"-",0,2)-StringInStr($currLine,"-",0,1))) $txtTmp=StringReplace($parsedString[3],"_"," ") $parsedString[3]=$txtTmp $txtTmp=StringStripWS($parsedString[3],3) $parsedString[3]=$txtTmp ;SongID, $parsedString[4]=StringMid($currLine,StringInStr($currLine,"-",0,2)+1,(StringInStr($currLine,"-",0,3)-StringInStr($currLine,"-",0,2))) $txtTmp=StringReplace($parsedString[4],"_"," ") $parsedString[4]=$txtTmp $txtTmp=StringStripWS($parsedString[4],3) $parsedString[4]=$txtTmp ;vocal/non/perf. $txtTmp = StringRight($currLine,6) Switch ($txtTmp) Case $txtTmp = "NV.bin" $parsedString[5]="NV" Case $txtTmp = "PV.bin" $parsedString[5]="PV" Case $txtTmp = "-V.bin" $parsedString[5]="V" Case Else $parsedString[5]="ERROR" EndSwitch $txtTmp=StringReplace($parsedString[5],"_"," ") $parsedString[5]=$txtTmp $txtTmp=StringStripWS($parsedString[5],3) $parsedString[5]=$txtTmp Return $parsedString EndFunc Any guidance would be most appreciated... Link to comment Share on other sites More sharing options...
cppman Posted October 19, 2006 Share Posted October 19, 2006 (edited) Well, before line 79 i put a msgbox to see what the value of $numTitles was.. and it was 0. Dim $Library[$numTitles][6] would then be doing this: Dim $Library[0][6] Thus causing your error. Same thing with the line 24. try this: expandcollapse popup#include <ExcelCom.au3> #include <Process.au3> #include <GuiConstants.au3> #region --- GuiBuilder code Start --- ; Script generated by AutoBuilder 0.6 Prototype GuiCreate("MyGUI", 176, 166,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $Label_1 = GuiCtrlCreateLabel("Indexer", 10, 10, 70, 20) $List_2 = GuiCtrlCreateList("process", 10, 50, 160, 110) ;;;;;;;;;;;;;;;;;;;;;;;;;;MAIN SECTION;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; GuiSetState() While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case Else Opt("GUIOnEventMode", 1) _buildIndex() $arraySize = 10 ;;;;;;;;;;;;;;;;;;;;;;;;;THIS IS WHERE THE ERROR IN QUESTION IS HAPPENING;;;;;;;;;;;;;;;;;;; Dim $newIndex[$arraySize][6] $newIndex = _buildIndex() $name = @MON & "-" & @MDAY & "-" & @YEAR & "-CDG_Library" _createXLIndex($newIndex, "X:\", $name) EndSelect WEnd Exit ;;;;;;;;;;;;;;;;;;;;;;;;;;MAIN SECTION;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; #endregion --- GuiBuilder generated code End --- Func _buildIndex() ;builds the file index, parses the names, and then returns an array with the library ;@extended = size of returned array $numTitles = 0;total number of titles $alTotal = 0 $mzTotal = 0 GUICtrlSetData($List_2,"building index") FileChangeDir("X:\") _RunDos("dir /s /b *.bin > a-l.txt") FileChangeDir("Y:\") _RunDos("dir /s /b *.bin > m-z.txt") $alIndex = FileOpen("x:\a-l.txt",0) $mzIndex = FileOpen("Y:\m-z.txt",0) GUICtrlSetData($List_2,"counting lines") $complete = false $fileLine = 1 While $complete = false ;count the files from a-l index $currLine = FileReadLine($alIndex,$fileLine) $currLen=StringLen($currLine) If $currLen = 0 Then $complete = True ElseIf StringInStr($currLine,".bin") Then $numTitles +=1 $alTotal +=1 EndIf $fileLine +=1 WEnd ;count the files from the m-z index $complete = false $fileLine = 1 While $complete = false ;count the files from a-l index $currLine = FileReadLine($mzIndex,$fileLine) $currLen=StringLen($currLine) If $currLen = 0 Then $complete = True ElseIf StringInStr($currLine,".bin") Then $numTitles +=1 $alTotal +=1 EndIf $fileLine +=1 WEnd GUICtrlSetData($List_2,"creating arrays") ;size an array to be of the size of the total number of files if ($numTitles <= 0) then $numTitles = 1 Dim $Library[$numTitles][6];entire library Dim $tmpArray[6];temporary storage from the parser ;re-read each index into a string GUICtrlSetData($List_2,"parsing lines") $complete = false While $complete = false ;parse the files from a-l index for $i = 0 to ($alTotal-1) $currLine = FileReadLine($alIndex,$i+1) $tmpArray = _stringParse($currLine) For $j = 0 to 5 $Library[$i][$j]=$tmpArray[$j] GUICtrlSetData($List_2,$Library[$i][$j]) Next Next ;parse the files from m-z index for $i = $alTotal to ($numTitles-1) $currLine = FileReadLine($mzIndex,$i+1) $tmpArray = _stringParse($currLine) For $j = 0 to 5 $Library[$i][$j]=$tmpArray[$j] GUICtrlSetData($List_2,$Library[$i][$j]) Next Next $complete = True WEnd FileClose($alIndex) FileClose($mzIndex) Return $Library SetExtended($numTitles) ;return the complete array value EndFunc Func _createXLIndex(ByRef $Library, $path, $fileName) ;takes in a 2 dimensional array, a path, and a file name and creates an XL sheet containing a song index ;$path should have the trailing \ ex C:\temp\ $s_FilePath = $path & $fileName _XLCreateBlank($s_FilePath) $rows = UBound($Library,1) For $i = 0 to ($rows-1) _XLWrite($s_FilePath,1,"A",$i+1,$Library[$i][0],0,0) _XLWrite($s_FilePath,1,"B",$i+1,$Library[$i][1],0,0) _XLWrite($s_FilePath,1,"C",$i+1,$Library[$i][2],0,0) _XLWrite($s_FilePath,1,"D",$i+1,$Library[$i][3],0,0) _XLWrite($s_FilePath,1,"E",$i+1,$Library[$i][4],0,0) _XLWrite($s_FilePath,1,"F",$i+1,$Library[$i][5],0,0) Next EndFunc Func _stringParse(ByRef $FN) dim $parsedString[6] ;takes in a path and filename, returns a 6 element array of the file data $txtTmp=StringStripWS($FN,3) $currLine=$txtTmp ;for each file, you should have 6 elements, ;path, $parsedString[0]=StringLeft($currLine,5) $txtTmp=StringReplace($parsedString[0],"_"," ") $parsedString[0]=$txtTmp $txtTmp=StringStripWS($parsedString[0],3) $parsedString[0]=$txtTmp ;filename, $parsedString[1]=StringRight($currLine, (StringLen($currLine)-5)) $txtTmp=StringReplace($parsedString[1],"_"," ") $parsedString[1]=$txtTmp $txtTmp=StringStripWS($parsedString[1],3) $parsedString[1]=$txtTmp ;Title, $parsedString[2]=StringMid($currLine,6,(StringInStr($currLine,"-")-5)) $txtTmp=StringReplace($parsedString[2],"_"," ") $parsedString[2]=$txtTmp $txtTmp=StringStripWS($parsedString[2],3) $parsedString[2]=$txtTmp ;Artist, $parsedString[3]=StringMid($currLine,StringInStr($currLine,"-",0,1)+1,(StringInStr($currLine,"-",0,2)-StringInStr($currLine,"-",0,1))) $txtTmp=StringReplace($parsedString[3],"_"," ") $parsedString[3]=$txtTmp $txtTmp=StringStripWS($parsedString[3],3) $parsedString[3]=$txtTmp ;SongID, $parsedString[4]=StringMid($currLine,StringInStr($currLine,"-",0,2)+1,(StringInStr($currLine,"-",0,3)-StringInStr($currLine,"-",0,2))) $txtTmp=StringReplace($parsedString[4],"_"," ") $parsedString[4]=$txtTmp $txtTmp=StringStripWS($parsedString[4],3) $parsedString[4]=$txtTmp ;vocal/non/perf. $txtTmp = StringRight($currLine,6) Switch ($txtTmp) Case $txtTmp = "NV.bin" $parsedString[5]="NV" Case $txtTmp = "PV.bin" $parsedString[5]="PV" Case $txtTmp = "-V.bin" $parsedString[5]="V" Case Else $parsedString[5]="ERROR" EndSwitch $txtTmp=StringReplace($parsedString[5],"_"," ") $parsedString[5]=$txtTmp $txtTmp=StringStripWS($parsedString[5],3) $parsedString[5]=$txtTmp Return $parsedString EndFunc Edited October 19, 2006 by CHRIS95219 Miva OS Project Link to comment Share on other sites More sharing options...
J_Y_C Posted October 19, 2006 Author Share Posted October 19, 2006 Thanks for the fast response. I see what you did to change it, and while that kind of worked, it doesn't really solve my problem, as the index size and therefore the array sizes will be different daily. In addition, I just realized that calling the _buildIndex() function twice is unnecessary. Isn't it funny just how much talking about a problem presents it's own solutions? So, instead of setting the size of the array into @extended, I just put the arraysize into the $arraysize variable like so: $newIndex = _buildIndex() $arraySize = UBound($newIndex,1) but now I am getting a different error with the _function to add the data to excel. But, I think I need to do some reading on excelCOM before I ask questions about that. Thanks chris.... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now