Jump to content

Array variable has incorrect. Please give me advice


KORN
 Share

Recommended Posts

Hi all 

          I found an error i n my file when i run. This result is get check Getway and get IPAddress that I want it.

image.thumb.png.f82da7ff88eb67f44f733c6be2d84dce.png

         But but in the same file the same code,same autoit version 3.3.14.5 but run in another computer can run and get the result as I want. My file as attached.

Please you all give me advice. Thank you.

image.thumb.png.4b01681a54676f94ee9210b7964b6ebb.png

 

 

CheckIP.au3 CheckIP.au3

Link to comment
Share on other sites

...
Func _CompareIP($Gateway,$IP)
    $GatewayArr= StringSplit($Gateway,".")
    If $GatewayArr[0] < 3 Then return "None"
    $Network = $GatewayArr[1]&"."&$GatewayArr[2]&"."&$GatewayArr[3]

    $IPArr = StringSplit($IP,".")
    If $IPArr[0] < 3 Then return "None"
    $Network1 = $IPArr[1]&"."&$IPArr[2]&"."&$IPArr[3]
...

EDIT:

This is fix to only avoid hard crash at attempt to accessing bad (not existent) array index.

Source of problem is somewhere else in your script ...

Just add debugging/logging ConsoleWrite/FileWrite to see content of your variables during execution ...

Edited by Zedna
Link to comment
Share on other sites

#include <File.au3>
Global $Gateway
global $log=_TempFile("","","",""),$value=1
$IPAddress =_CheckIP()
splashoff()
msgbox("","",$IPAddress)
Func _CheckIP()
    local $SplashTextOn=SplashTextOn("time","",100,40)
    local $hTimer = TimerInit()
    local $pid=run(@ComSpec & " /c " &"Tracert -h "&$value&" 10.24.100.10>"&$log,"",@SW_HIDE)
    while 1
        ControlSetText($SplashTextOn,'','Static1',round(TimerDiff($hTimer)/1000,0))
        if not ProcessExists($pid) then exitloop
    wend
    ControlSetText($SplashTextOn,'','Static1',"wait")
    $CheckIP = "None"
    IF @IPAddress1 <> "0.0.0.0" Then
        $CheckIP = _CheckLog(@IPAddress1)
    EndIF
    IF @IPAddress2 <> "0.0.0.0" and $CheckIP = "None" Then
        $CheckIP = _CheckLog(@IPAddress2)
    EndIf
    IF @IPAddress3 <> "0.0.0.0" and $CheckIP = "None" Then
        $CheckIP = _CheckLog(@IPAddress3)
    EndIf
    IF @IPAddress4 <> "0.0.0.0" and $CheckIP = "None" Then
        $CheckIP = _CheckLog(@IPAddress4)
    EndIf
    return $CheckIP
EndFunc

Func _CheckLog($IPAddress)
    $found = 0
    For $row = 1 to _FileCountLines($log)
        $word = FileReadLine($log,$row)
        $data = StringSplit($word," ")
        For $i = 1 to $data[0]
            $dataarr= StringSplit($data[$i],".")
            IF $dataarr[0] = 4 and $dataarr[4] <> "com" Then
                $found = $found + 1
                IF $found = 2 Then
                    IF StringLeft($data[$i],1) = "[" Then
                        $Gateway1 = StringSplit($data[$i],"[")
                        $Gateway2 = StringSplit($Gateway1[2],"]")
                        $Gateway = $Gateway2[1]
                        ExitLoop
                    Else
                        $Gateway = $data[$i]
                        ExitLoop
                    EndIF
                EndIF
            EndIF
        Next
    Next
    filedelete($log)
return _CompareIP($Gateway,$IPAddress)
EndFunc

Func _CompareIP($Gateway,$IP)
    $GatewayArr= StringSplit($Gateway,".")
    If $GatewayArr[0] < 3 Then return seterror(1,0,"None")
    $Network = $GatewayArr[1]&"."&$GatewayArr[2]&"."&$GatewayArr[3]
    $IPArr = StringSplit($IP,".")
    If $IPArr[0] < 3 Then return seterror(2,0,"None")
    $Network1 = $IPArr[1]&"."&$IPArr[2]&"."&$IPArr[3]
    IF $Network = $Network1 or ($Network='10.24.104' and $Network1='10.24.105') Then
        return seterror(0,0,$IP)
    Else
        return seterror(3,0,"None")
    EndIF
EndFunc

 

Edited by bdr529
return seterror

To community goes all my regards and thanks

Link to comment
Share on other sites

12 hours ago, bdr529 said:
#include <File.au3>
Global $Gateway
global $log=_TempFile("","","",""),$value=1
$IPAddress =_CheckIP()
splashoff()
msgbox("","",$IPAddress)
Func _CheckIP()
    local $SplashTextOn=SplashTextOn("time","",100,40)
    local $hTimer = TimerInit()
    local $pid=run(@ComSpec & " /c " &"Tracert -h "&$value&" 10.24.100.10>"&$log,"",@SW_HIDE)
    while 1
        ControlSetText($SplashTextOn,'','Static1',round(TimerDiff($hTimer)/1000,0))
        if not ProcessExists($pid) then exitloop
    wend
    ControlSetText($SplashTextOn,'','Static1',"wait")
    $CheckIP = "None"
    IF @IPAddress1 <> "0.0.0.0" Then
        $CheckIP = _CheckLog(@IPAddress1)
    EndIF
    IF @IPAddress2 <> "0.0.0.0" and $CheckIP = "None" Then
        $CheckIP = _CheckLog(@IPAddress2)
    EndIf
    IF @IPAddress3 <> "0.0.0.0" and $CheckIP = "None" Then
        $CheckIP = _CheckLog(@IPAddress3)
    EndIf
    IF @IPAddress4 <> "0.0.0.0" and $CheckIP = "None" Then
        $CheckIP = _CheckLog(@IPAddress4)
    EndIf
    return $CheckIP
EndFunc

Func _CheckLog($IPAddress)
    $found = 0
    For $row = 1 to _FileCountLines($log)
        $word = FileReadLine($log,$row)
        $data = StringSplit($word," ")
        For $i = 1 to $data[0]
            $dataarr= StringSplit($data[$i],".")
            IF $dataarr[0] = 4 and $dataarr[4] <> "com" Then
                $found = $found + 1
                IF $found = 2 Then
                    IF StringLeft($data[$i],1) = "[" Then
                        $Gateway1 = StringSplit($data[$i],"[")
                        $Gateway2 = StringSplit($Gateway1[2],"]")
                        $Gateway = $Gateway2[1]
                        ExitLoop
                    Else
                        $Gateway = $data[$i]
                        ExitLoop
                    EndIF
                EndIF
            EndIF
        Next
    Next
    filedelete($log)
return _CompareIP($Gateway,$IPAddress)
EndFunc

Func _CompareIP($Gateway,$IP)
    $GatewayArr= StringSplit($Gateway,".")
    If $GatewayArr[0] < 3 Then return seterror(1,0,"None")
    $Network = $GatewayArr[1]&"."&$GatewayArr[2]&"."&$GatewayArr[3]
    $IPArr = StringSplit($IP,".")
    If $IPArr[0] < 3 Then return seterror(2,0,"None")
    $Network1 = $IPArr[1]&"."&$IPArr[2]&"."&$IPArr[3]
    IF $Network = $Network1 or ($Network='10.24.104' and $Network1='10.24.105') Then
        return seterror(0,0,$IP)
    Else
        return seterror(3,0,"None")
    EndIF
EndFunc

 

I have tested, Can get result as I want it that great. Thank you so much for you help.

Link to comment
Share on other sites

15 hours ago, Zedna said:
...
Func _CompareIP($Gateway,$IP)
    $GatewayArr= StringSplit($Gateway,".")
    If $GatewayArr[0] < 3 Then return "None"
    $Network = $GatewayArr[1]&"."&$GatewayArr[2]&"."&$GatewayArr[3]

    $IPArr = StringSplit($IP,".")
    If $IPArr[0] < 3 Then return "None"
    $Network1 = $IPArr[1]&"."&$IPArr[2]&"."&$IPArr[3]
...

EDIT:

This is fix to only avoid hard crash at attempt to accessing bad (not existent) array index.

Source of problem is somewhere else in your script ...

Just add debugging/logging ConsoleWrite/FileWrite to see content of your variables during execution ...

Thank you so much for you recommended.

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