Jump to content

Autoit code problem - looping


Recommended Posts

hi,

I have a problem with my autoit code that it is crashes after 8 loops. now, the reason for the crash is not-known, because if taking the 8 loop step out from the script to another script and run it there it is running fine.

the thing is that I am using Arrays (Alot of them as you can see), and variables like $s many times rerwrite on them.

is this a problem? using the same variables names and rewrite on them ?

if running the 8 loop step on a new autoit script (.exe file) it runs fine if I call it from the original script.

I have no idea why it crashes, anyone?

#AutoIt3Wrapper_run_debug_mode=Y
#include <String.au3>
#include <Array.au3>
#include <String.au3>
#include <File.au3>

;=========================================start delete old files=================
If FileExists("C:\erez.txt") Then
    FileDelete("c:\erez.txt")
    FileDelete("c:\erez1.txt")
    FileDelete("c:\erez3.txt")
    FileDelete("c:\erezlast.txt")
EndIf

FileDelete("c:\list bcms skill*.txt")
FileDelete("c:\list bcms vdn*.txt")

;=================================================================================
;=========================settings varibles=======================================

Global $SkillVdn[20],$FirstArray[25],$SecondArray[25]
Global $FinalFile = "c:\aes_ip\vdntest.txt"
_FileReadToArray("c:\skill.ini", $SkillVdn)

;==========================opening Telnet session=================================
TCPStartup()
Dim $szServerPC = "9.148.218.20"
Dim $szIPADDRESS = "9.148.218.20"
Dim $nPORT = 23
Dim $ConnectedSocket = -1
$ConnectedSocket = TCPConnect($szIPADDRESS, $nPORT)
Sleep(600)
TCPSend($ConnectedSocket, Binary("0xfffb18fffb1f"))
TCPSend($ConnectedSocket, Binary("0xfffc20fffc23fffb27"))
Sleep(200)
TCPSend($ConnectedSocket, Binary("0xfffa1f00500019fff0"))
Sleep(200)
TCPSend($ConnectedSocket, Binary("0xfffa2700fff0"))
TCPSend($ConnectedSocket, Binary("0xfffa1800414e5349fff0"))
Sleep(200)
TCPSend($ConnectedSocket, Binary("0xfffd03"))
Sleep(10)
TCPSend($ConnectedSocket, Binary("0xfffb01fffe05fffc21"))
Sleep(200)
TCPSend($ConnectedSocket, Binary("0xfffc01"))
Sleep(200)
TCPSend($ConnectedSocket, Binary("0xfffd01"))
Sleep(1000)
TCPSend($ConnectedSocket, Binary("0x69"))
Sleep(200)
TCPSend($ConnectedSocket, Binary("0x62"))
Sleep(200)
TCPSend($ConnectedSocket, Binary("0x6d"))
Sleep(200)
TCPSend($ConnectedSocket, Binary("0x0d"))
Sleep(1000)
TCPSend($ConnectedSocket, Binary("0x69"))
Sleep(200)
TCPSend($ConnectedSocket, Binary("0x626d"))
Sleep(200)
TCPSend($ConnectedSocket, Binary("0x34"))
Sleep(200)
TCPSend($ConnectedSocket, Binary("0x69"))
Sleep(200)
TCPSend($ConnectedSocket, Binary("0x7372"))
Sleep(200)
TCPSend($ConnectedSocket, Binary("0x0d"))
Sleep(1000)
TCPSend($ConnectedSocket, Binary("0x77"))
Sleep(200)
TCPSend($ConnectedSocket, Binary("0x32"))
Sleep(200)
TCPSend($ConnectedSocket, Binary("0x6b74"))
Sleep(200)
TCPSend($ConnectedSocket, Binary("0x74"))
Sleep(200)
TCPSend($ConnectedSocket, Binary("0x0d"))
Sleep(600)
;=================================================================================
;======================Main Proc==================================================

For $i0 = 1 To $SkillVdn[0]
    if $i0=8 Then ExitLoop
    $kp0 = $SkillVdn[$i0]
    $kp1 = StringSplit($kp0, ",", 1)
    $kp2 = $kp1[1]
    $kp3 = $kp1[2]
    _SkillVdn($kp2, $kp3)
;_ArrayDisplay($FirstArray)
;_ArrayDisplay($SecondArray)
    For $i1 = 1 To 24
        $Finalstring = $FirstArray[$i1] & "," & $SecondArray[$i1]
        $openfile = FileOpen("c:\aes_ip\vdntest.txt", 1)
        FileWriteLine($openfile, $Finalstring &@CRLF)
        FileClose($openfile)
    Next
    Dim $FirstArray [25]
    Dim $SecondArray [25]

Next
TCPCloseSocket ($ConnectedSocket)
TCPShutdown()

run ("c:\Peilim-new-reporting2.exe")
Exit

;=================================================================================
;=======================_SkillVdn proc============================================

Func _SkillVdn($kc2, $kc3)
;===============list bcms skill <number>===============
    $a = "list bcms skill " & $kc2
    TCPSend($ConnectedSocket, $a)
    Sleep(200)
    TCPSend($ConnectedSocket, Binary("0x0d"))
    $m = TCPRecv($ConnectedSocket, 16000, 0)
    Sleep(1000)
    $m = TCPRecv($ConnectedSocket, 16000, 0)
    TCPSend($ConnectedSocket, Binary("0x1b6e"))
    Sleep(1000)
    $n = TCPRecv($ConnectedSocket, 16000, 0)
    Sleep(1000)
    TCPSend($ConnectedSocket, Binary("0x1b6e"))
    Sleep(1000)
    $R = TCPRecv($ConnectedSocket, 16000, 1)
    Sleep(1000)
    $k = TCPRecv($ConnectedSocket, 16000, 1)
    $j = FileOpen("c:\erez.txt", 2)
    FileWrite("c:\erez.txt", $m)
    FileWrite("c:\erez.txt", $n)
    FileWrite("c:\erez.txt", $R)
    FileWrite("c:\erez.txt", $k)
    FileClose($j)
;=======================Data manipulation===================================
    Local $E[500]
    Local $U[500]
    $FileOrig = "c:\erez.txt"
    $sfileread = FileRead($FileOrig)
    $sfileread = StringReplace($sfileread, Chr(0), "")
    $FileResult = "c:\erez1.txt"
    $hFile = FileOpen($FileResult, 2)
    FileWrite($hFile, $sfileread)
    FileClose($hFile)
    _FileReadToArray("c:\erez1.txt", $E)
    $ttt = UBound($E)
    Dim $EREZ1[500]
    Dim $EREZ[500]
    Dim $EREZ2[500]
    _FileReadToArray("c:\erez1.txt", $EREZ)
;_Arraydisplay ($EREZ)
    $E1 = _ArraySearch($EREZ, "Switch Name:", 0, 0, 1, 1)
    For $b = 0 To 16
        If $E1 + $b >= $ttt Then ExitLoop
        _ArraySwap($EREZ[$E1 + $b], $EREZ1[$b + 1])
    Next
    For $b = 16 To 24
        If $E1 + 16 + ($b - 5) >= $ttt Then ExitLoop
        _ArraySwap($EREZ[$E1 + 16 + ($b - 5)], $EREZ1[$b + 2])
        
    Next
    For $b = 24 To 31
        If $E1 + 16 + ($b + 6) >= $ttt Then ExitLoop
        _ArraySwap($EREZ[$E1 + 16 + ($b + 6)], $EREZ1[$b + 3])
        If @error Then ExitLoop
    Next
    $EREZ2 = $EREZ1
    $R = $EREZ2[0]
    For $i = 1 To 34
        $m = $EREZ2[$i]
        $s = "                                                                              "
        
        Do
            $p1 = StringInStr($m, Chr(27), 1)
            If $p1 = 0 Then ExitLoop
            $p2 = StringInStr($m, "H", 1, 1)
            $p3 = ($p2 - $p1) + 1
            $n = StringMid($m, $p1, $p3)
            $nn1 = StringSplit($n, ";", 1)
            If @error Then ExitLoop
            $nn2 = $nn1[2]
            $nn3 = StringTrimRight($nn2, 1)
            $t = StringReplace($m, $n, "")
            $p3 = StringInStr($m, "H", 1, 1)
            $p4 = StringInStr($m, Chr(27), 1, 2)
            $p3 = $p3 + 1
            $p5 = ($p4 - $p3)
            $n1 = StringMid($m, $p3, $p5)
            $s = _StringInsert($s, $n1, Number($nn3))
            $m = $t
        Until $p1 = 0
        $readline = "list bcms skill " & $kc2
        $jj1 = "c:\" & $readline & ".txt"
        FileOpen($jj1, 1)
        FileWriteLine($jj1, $s)
    Next
    local $R[800]
    $m = FileOpen($jj1, 0)
    $n = FileRead($m)
    _FileReadToArray($jj1, $R)
;_ArrayDisplay ($R)
    $splitnumber = $R[2]
    $splitnumber = StringSplit($splitnumber, ":", 1)
    $splitnumber = $splitnumber[2]
    $splitnumber = StringStripWS($splitnumber, 2)
    $splitnumber = $splitnumber & ","
    $splitname = $R[3]
    $splitname = StringSplit($splitname, ":", 1)
    $splitname = $splitname[2]
    $splitname = StringTrimRight($splitname, 24)
    $splitname = StringStripWS($splitname, 2)
    $splitnumber = $splitnumber & $splitname & "," & @YEAR & @MON & @MDAY & @HOUR & @MIN
    $rr1 = 9
    For $z = 1 To 24
        _ArraySwap($R[$rr1], $U[$z])
        $rr1 = $rr1 + 1
    Next
    
    For $i = 1 To 24
        $z = $U[$i]
        $t1 = StringSplit($z, ":", 1)
        $t1 = $t1[1]
        $o = StringRight($z, 71)
        $o = StringLeft($o, 3)
        $C = StringIsSpace($o)
        If $C = 1 Then $o = "0,"
        If $C = 0 Then $o = ""
        $k = StringStripWS($z, 2)
        $k = StringRegExpReplace($z, '\s{2,27}', ",")
        $k = StringTrimLeft($k, 1)
        If $t1 <= 9 Then $k = "0" & $k
        $k = StringTrimRight($k, 2)
        $k = StringReplace($k, "-", ",", 1)
        $k = $k & $o & $splitnumber
        _ArrayInsert($FirstArray, $i, $k)
    Next
    
;==========================getting VDN information also================
;======================================================================
    $a = "list bcms vdn " & $kc3
    TCPSend($ConnectedSocket, $a)
    Sleep(200)
    TCPSend($ConnectedSocket, Binary("0x0d"))
    $m = TCPRecv($ConnectedSocket, 16000, 0)
    Sleep(1000)
    $m = TCPRecv($ConnectedSocket, 16000, 0)
    TCPSend($ConnectedSocket, Binary("0x1b6e"))
    Sleep(1000)
    $n = TCPRecv($ConnectedSocket, 16000, 0)
    Sleep(1000)
    TCPSend($ConnectedSocket, Binary("0x1b6e"))
    Sleep(1000)
    $R = TCPRecv($ConnectedSocket, 16000, 1)
    Sleep(1000)
    $k = TCPRecv($ConnectedSocket, 16000, 1)
    $j = FileOpen("c:\erez.txt", 2)
    FileWrite("c:\erez.txt", $m)
    FileWrite("c:\erez.txt", $n)
    FileWrite("c:\erez.txt", $R)
    FileWrite("c:\erez.txt", $k)
    FileClose($j)
;=======================Data manipulation===================================
    Local $E[500]
    Local $U[500]
    $FileOrig = "c:\erez.txt"
    $sfileread = FileRead($FileOrig)
    $sfileread = StringReplace($sfileread, Chr(0), "")
    $FileResult = "c:\erez1.txt"
    $hFile = FileOpen($FileResult, 2)
    FileWrite($hFile, $sfileread)
    FileClose($hFile)
    _FileReadToArray("c:\erez1.txt", $E)
    $ttt = UBound($E)
    Dim $EREZ1[500]
    Dim $EREZ[500]
    Dim $EREZ2[500]
    _FileReadToArray("c:\erez1.txt", $EREZ)
    
    $E1 = _ArraySearch($EREZ, "Switch Name:", 0, 0, 1, 1)
    For $b = 0 To 16
        If $E1 + $b >= $ttt Then ExitLoop
        _ArraySwap($EREZ[$E1 + $b], $EREZ1[$b + 1])
    Next
    For $b = 16 To 24
        If $E1 + 16 + ($b - 5) >= $ttt Then ExitLoop
        _ArraySwap($EREZ[$E1 + 16 + ($b - 5)], $EREZ1[$b + 2])
        
    Next
    For $b = 24 To 31
        If $E1 + 16 + ($b + 6) >= $ttt Then ExitLoop
        _ArraySwap($EREZ[$E1 + 16 + ($b + 6)], $EREZ1[$b + 3])
        If @error Then ExitLoop
    Next
    $EREZ2 = $EREZ1
    $R = $EREZ2[0]
    For $i = 1 To 34
        $m = $EREZ2[$i]
        $s = "                                                                              "
        
        Do
            $p1 = StringInStr($m, Chr(27), 1)
            If $p1 = 0 Then ExitLoop
            $p2 = StringInStr($m, "H", 1, 1)
            $p3 = ($p2 - $p1) + 1
            $n = StringMid($m, $p1, $p3)
            $nn1 = StringSplit($n, ";", 1)
            If @error Then ExitLoop
            $nn2 = $nn1[2]
            $nn3 = StringTrimRight($nn2, 1)
            $t = StringReplace($m, $n, "")
            $p3 = StringInStr($m, "H", 1, 1)
            $p4 = StringInStr($m, Chr(27), 1, 2)
            $p3 = $p3 + 1
            $p5 = ($p4 - $p3)
            $n1 = StringMid($m, $p3, $p5)
            $s = _StringInsert($s, $n1, Number($nn3))
            $m = $t
        Until $p1 = 0
        $readline = "list bcms vdn " & $kc3
        $jj1 = "c:\" & $readline & ".txt"
        FileOpen($jj1, 1)
        FileWriteLine($jj1, $s)
    Next
    Dim $R
    Dim $E[500]
    $m = FileOpen($jj1, 0)
    $n = FileRead($m)
    _FileReadToArray($jj1, $R)
    $rr1 = 9
    For $z = 1 To 24
        _ArraySwap($R[$rr1], $E[$z])
        $rr1 = $rr1 + 1
    Next
    For $i = 1 To 24
        $m = $E[$i]
        $t = StringRegExp($m, '\s\d{1,3}\s', 3, 1)
        $SecondArray[$i] = $t[0] & "," & $t[2] & "," & $t[3]
    Next
    
    
EndFunc  ;==>_SkillVdn

now, the line

if $i0=8 Then ExitLoop

makes the script call another one, that have the exact same lines, but $i0 start with 8, and the line "if $i0=8 Then ExitLoop" does not exist there.

Link to comment
Share on other sites

Hi.

Freqent modifications of Variables (and Arrays) is no problem at all.

IMHO the first step is to know where EXACTLY the code crashes. When you start it from SciTE, what's the output there?

Checkout what's the line number, your code crashes, see the FAQ "debugging" for howto. Then track down why it crashes there.

Regards, Rudi.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

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