Sign in to follow this  
Followers 0
DrewSS

incorrect number of subscripts Error handling

5 posts in this topic

#1 ·  Posted (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 by DrewSS

Share this post


Link to post
Share on other sites



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

1 person likes this

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

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

1 person likes this

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My 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

 

Share this post


Link to post
Share on other sites

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

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  
Followers 0