Sign in to follow this  
Followers 0
Naveed

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

3 posts in this topic

#include <ExcelCOM_UDF.au3>

    $file = @ScriptDir & "\resource\Subnets.xlsx"
    $oExcel = _ExcelBookOpen($file, 0) 
    ; 10.225.211.91
    ; 172.17.144.24

    $ip1 = "10.225.211.91"
    $ip2 = StringSplit($ip1, ".")
    $sFindWhat = $ip2[1] & "." & $ip2[2] & "." & $ip2[3]
    $sRangeOrRowStart = "A1"
    $iRowEnd = "500"
    $StrRow = _ExcelFindInRange($oExcel, $sFindWhat, $sRangeOrRowStart,$iRowEnd)
    $check = StringLen($StrRow[1][0])
    MsgBox(1,"",$StrRow[1][0])
    If $check < 1 Then
        MsgBox(1,"","doesnt Exist")
    Else
    $check = StringLen($StrRow[1][0])
    MsgBox(1,"",$check)
    MsgBox(1,"",$StrRow[1][0])
    $result = StringTrimLeft($StrRow[1][0], 1)
    $read = "C" & $result
    $match = _ExcelReadCell($oExcel, $read, 1)
    MsgBox(1,"",$match)
    EndIf
    _ExcelBookClose($oExcel, 0, 0)

I am getting the above error when i am trying to search for an ip address from an excel sheet, the excel sheet has a list of subnets and matching locations.

If the ip address exists on the subnets list then it works fine and returns the corresponding location, however when the ip address is not on the list then i get the Error.

Can anybody help with either a solution or some sort of error capture to stop the script from crashing. i have tried a simple IF statement but it also errors before the error can be captured.

NB - the extra msgbox's are just there to try and capture the error.

Any assistance will be much appreciated.

Share this post


Link to post
Share on other sites



At which line does this error occur? Shouldn't be too hard to solve then.

Btw I see you only search for the first 3 bytes of the IP address ($sFindWhat), which you can also extract from $ip1 without an extra variable $ip2:

$ip = "192.168.0.1"
$First3Bytes = StringRegExpReplace($ip, "(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})", "\1.\2.\3")

Share this post


Link to post
Share on other sites

At which line does this error occur? Shouldn't be too hard to solve then.

Btw I see you only search for the first 3 bytes of the IP address ($sFindWhat), which you can also extract from $ip1 without an extra variable $ip2:

$ip = "192.168.0.1"
$First3Bytes = StringRegExpReplace($ip, "(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})", "\1.\2.\3")

Thanks for the reply, I figured it out, right after i posted this topic.

I added the following line of code and it works a treat.

$check1 = $StrRow[0][0]
If $check1 = 0 Then

This basically looks at the number of results returned and if it is 0 then ends the check.

Regards

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