DrewSS Posted February 10, 2015 Share Posted February 10, 2015 (edited) Hello, I'm doing some recursive stringsplitting with If statements on array placements, but some of my files dont have all the correct sized arrays so I'm getting this error: ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded. Is there a way to catch the error and continue the script or ignore the error basically? ex code: $filelist = _FileListToArray($sDestPath, "sf*") For $read = 1 to UBound($filelist) -1 $filepath = @ScriptDir & "\extracts\" & $filelist[$read] _FileReadToArray($filepath, $tempA, "") For $line = 1 To UBound($tempA) -1 StringReplace($tempA[$line]," ", " ") $word = StringSplit($tempA[$line], " ") $stat_chain = $word[3] $stat_store = $word[4] If $word[7] = "PRINTER***No" Then $printercount +=1 If $word[7] = "PRINTER***Paper" Then $printercount +=1 If $word[8] = "3DBUILDDATE" Then $dbdate = $word[7] If $word[8] = "COUPONS" AND $word[9] = "TRIGGERED" And $word[7] = "0000" Then $zerocoupcount +=1 Next $currentDBDate = StringLeft($dbdate, 10) _DateTimeSplit($currentDBDate & "", $compareDBdate, $bMyTime) $compareB = $compareDBdate[2] $compare = $compareA - $compareB If $compare > 2 Then $dbcount += 1 ConsoleWrite($stat_chain & "-" & $stat_store & @CRLF & "Printer issues: " & $printercount & @CRLF & "Zero Coupon: " & $zerocoupcount & @CRLF & "Database: " & $dbcount & @CRLF & @CRLF) Next Out of 70,000 + files, occasionally some of the lines dont have 8 delimiters and cause the script to break at $word[8] . I'm still relatively new to programming and have not gotten into error handling yet. Please help! Edited February 10, 2015 by DrewSS Link to comment Share on other sites More sharing options...
Solution JohnOne Posted February 10, 2015 Solution Share Posted February 10, 2015 If $word[7] = "PRINTER***No" Then $printercount += 1 If $word[7] = "PRINTER***Paper" Then $printercount += 1 If UBound($word) > 8 If $word[8] = "3DBUILDDATE" Then $dbdate = $word[7] If $word[8] = "COUPONS" And $word[8] = "TRIGGERED" And $word[7] = "0000" Then $zerocoupcount += 1 EndIf DrewSS 1 AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
MikahS Posted February 10, 2015 Share Posted February 10, 2015 $filelist[0] will show the number of elements, that can be used to stop at a certain number. Also, the second call to _FileReadToArray has no variable storing it. DrewSS 1 Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ Link to comment Share on other sites More sharing options...
JohnOne Posted February 10, 2015 Share Posted February 10, 2015 You cannot deal with such a runtime error and continue script, you have to code in such a way as to avoid such errors. DrewSS 1 AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
DrewSS Posted February 10, 2015 Author Share Posted February 10, 2015 Thank you JohnOne!! This is excellent knowledge, and your code worked exactly how I needed. Working code: $filelist = _FileListToArray($sDestPath, "sf*") For $read = 1 to UBound($filelist) -1 $filepath = @ScriptDir & "\extracts\" & $filelist[$read] _FileReadToArray($filepath, $tempA, "") For $line = 1 To UBound($tempA) -1 StringReplace($tempA[$line]," ", " ") $word = StringSplit($tempA[$line], " ") $stat_chain = $word[3] $stat_store = $word[4] If $word[7] = "PRINTER***No" Then $printercount +=1 If $word[7] = "PRINTER***Paper" Then $printercount +=1 If UBound($word) > 8 Then If $word[8] = "3DBUILDDATE" Then $dbdate = $word[7] If $word[8] = "COUPONS" AND $word[9] = "TRIGGERED" And $word[7] = "0000" Then $zerocoupcount +=1 EndIf Next $currentDBDate = StringLeft($dbdate, 10) _DateTimeSplit($currentDBDate & "", $compareDBdate, $bMyTime) $compareB = $compareDBdate[2] $compare = $compareA - $compareB If $compare > 2 Then $dbcount += 1 ConsoleWrite($stat_chain & "-" & $stat_store & @CRLF & "Printer issues: " & $printercount & @CRLF & "Zero Coupon: " & $zerocoupcount & @CRLF & "Database: " & $dbcount & @CRLF & @CRLF) Next 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