erezlevi Posted February 8, 2008 Share Posted February 8, 2008 hi, I have the following function that what it does is creating a GUI interface that shows "agents status". I need this GUI to refresh every 10 sec, so, I did it, but the problem is I can't close the GUI anymore, I thought about using a While statment but I can't because of the 10 Sec period of sleep (10000). what is the best way to do it? don't try to run the script because it needs two files, and a Telnet connection to a server. expandcollapse popupFunc erez2() Local $EREZ[500] $FileOrig = "c:\erez.txt" $sfileread = FileRead($FileOrig) $sfileread = StringReplace($sfileread, Chr(0), "") ;$sfileread = StringReplace($sfileread, Chr(13), "") $FileResult = "c:\erez1.txt" $hFile = FileOpen($FileResult, 2) FileWrite($hFile, $sfileread) FileClose($hFile) $Read = FileRead("c:\erez.txt") $Replace = StringReplace($Read, "", "") $Replace = StringReplace($Replace, Chr("7f"), "") $EREZ = StringSplit($Replace, "[") ; _ArrayDisplay($EREZ) $k = _ArraySearch($EREZ, "BCMS SKILL (AGENT) STATUS", 0, 0, 1, 1) ;MsgBox(0, "this is where $k is:", $k) $mmm1 = $EREZ[$k] $mmm2 = StringSplit($mmm1, "H") $mmm3 = $mmm2[2] $mmm11 = $EREZ[$k + 1] $mmm12 = StringSplit($mmm11, "H") $mmm13 = $mmm12[2] $mmm14 = $EREZ[$k + 2] $mmm15 = StringSplit($mmm14, "H") $mmm16 = $mmm15[2] $mmm20 = $EREZ[$k + 3] $mmm21 = StringSplit($mmm20, "H") $mmm22 = $mmm21[2] $mmm23 = $EREZ[$k + 4] $mmm24 = StringSplit($mmm23, "H") $mmm25 = $mmm24[2] $mmm30 = $EREZ[$k + 5] $mmm31 = StringSplit($mmm30, "H") $mmm32 = $mmm31[2] $mmm33 = $EREZ[$k + 6] $mmm34 = StringSplit($mmm33, "H") $mmm35 = $mmm34[2] $mmm40 = $EREZ[$k + 7] $mmm41 = StringSplit($mmm40, "H") $mmm42 = $mmm41[2] $mmm43 = $EREZ[$k + 8] $mmm44 = StringSplit($mmm43, "H") $mmm45 = $mmm44[2] $mmm50 = $EREZ[$k + 11] $mmm51 = StringSplit($mmm50, "H") $mmm52 = $mmm51[2] $mmm53 = $EREZ[$k + 12] $mmm54 = StringSplit($mmm53, "H") $mmm55 = $mmm54[2] $k = _ArraySearch($EREZ, "AGENT NAME", 0, 0, 1, 1) $H = GUICreate("Monitoring...", 400, 400, 100, 100) ; I need this to be able to refresh itself (it is working but flashes every 10 sec) $H1 = GUICtrlCreateLabel($mmm3, 100, 20) $H2 = GUICtrlCreateLabel($mmm13 & " " & $mmm16, 15, 50) $H3 = GUICtrlCreateLabel($mmm22 & " " & $mmm25, 240, 50) $H4 = GUICtrlCreateLabel($mmm32 & " " & $mmm35, 15, 90) $H5 = GUICtrlCreateLabel($mmm42 & " " & $mmm45, 240, 90) $H6 = GUICtrlCreateLabel($mmm52 & " " & $mmm55, 240, 110) $p = 170 For $i = 1 To 12 $agent0 = $EREZ[$k + 1] ;if @error then ExitLoop $agent1 = StringSplit($agent0, "H") If @error Then ExitLoop $agent2 = $agent1[2] $agent3 = $EREZ[$k + 2] $agent4 = StringSplit($agent3, "H") If @error Then ExitLoop $agent5 = $agent4[2] $agent6 = $EREZ[$k + 3] $agent7 = StringSplit($agent6, "H") If @error Then ExitLoop $agent8 = $agent7[2] $agent9 = $EREZ[$k + 4] $agent10 = StringSplit($agent9, "H") If @error Then ExitLoop $agent11 = $agent10[2] $H7 = GUICtrlCreateLabel($agent2, 25, $p) $H8 = GUICtrlCreateLabel($agent5 & " " & $agent8 & " " & $agent11, 150, $p) $p = $p + 20 $k = $k + 8 Next GUISetState() $msg = GUIGetMsg() FileDelete("c:\erez.txt") FileDelete("c:\erez1.txt") Sleep(10000) ;pause 10 sec for next refresh... TCPSend($ConnectedSocket, "0x1b78") Sleep(200) TCPSend($ConnectedSocket, $a) Sleep(100) 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) $p = StringLen($r) $j = FileOpen("c:\erez.txt", 1) FileWrite("c:\erez.txt", $m) FileWrite("c:\erez.txt", $n) FileWrite("c:\erez.txt", $r) FileClose($j) If $msg = $GUI_EVENT_CLOSE Then Exit ;not working I guess because of not usig a while loop, I need another solution. GUIDelete($H) ; deleting GUI. erez2() ; calling erez2 again every 10 sec. EndFunc ;==>erez2 Link to comment Share on other sites More sharing options...
PsaltyDS Posted February 8, 2008 Share Posted February 8, 2008 Looks to me like you are deleting it, then the function calls itself and immediately re-creates the GUI. The "blinking" is just the amount of time between deletion and re-creation of the GUI. You will eventually cause the script to crash for excessive recursion level with this method. The function should not be calling itself. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
erezlevi Posted February 8, 2008 Author Share Posted February 8, 2008 (edited) Looks to me like you are deleting it, then the function calls itself and immediately re-creates the GUI. The "blinking" is just the amount of time between deletion and re-creation of the GUI. You will eventually cause the script to crash for excessive recursion level with this method. The function should not be calling itself. first thanks, I fixed it. I'v changed GUIDelete with Guictrlsetdata, and use another call to another function that have a While statement. can you guys check if I have recursion problem here: expandcollapse popupIf $d <> 0 Then Call("erez1") If $d1 <> 0 Then ; if $d1 is different then 0 then call erez2 then call erez3 (which has a while loop). Call("erez2") Call("erez3") EndIf If $d2 <> 0 Then Call("erez1") Func erez2() Local $EREZ[500] $FileOrig = "c:\erez.txt" $sfileread = FileRead($FileOrig) $sfileread = StringReplace($sfileread, Chr(0), "") ;$sfileread = StringReplace($sfileread, Chr(13), "") $FileResult = "c:\erez1.txt" $hFile = FileOpen($FileResult, 2) FileWrite($hFile, $sfileread) FileClose($hFile) $Read = FileRead("c:\erez.txt") $Replace = StringReplace($Read, "", "") $Replace = StringReplace($Replace, Chr("7f"), "") $EREZ = StringSplit($Replace, "[") ; _ArrayDisplay($EREZ) $k = _ArraySearch($EREZ, "BCMS SKILL (AGENT) STATUS", 0, 0, 1, 1) ;MsgBox(0, "this is where $k is:", $k) $mmm1 = $EREZ[$k] $mmm2 = StringSplit($mmm1, "H") $mmm3 = $mmm2[2] $mmm11 = $EREZ[$k + 1] $mmm12 = StringSplit($mmm11, "H") $mmm13 = $mmm12[2] $mmm14 = $EREZ[$k + 2] $mmm15 = StringSplit($mmm14, "H") $mmm16 = $mmm15[2] $mmm20 = $EREZ[$k + 3] $mmm21 = StringSplit($mmm20, "H") $mmm22 = $mmm21[2] $mmm23 = $EREZ[$k + 4] $mmm24 = StringSplit($mmm23, "H") $mmm25 = $mmm24[2] $mmm30 = $EREZ[$k + 5] $mmm31 = StringSplit($mmm30, "H") $mmm32 = $mmm31[2] $mmm33 = $EREZ[$k + 6] $mmm34 = StringSplit($mmm33, "H") $mmm35 = $mmm34[2] $mmm40 = $EREZ[$k + 7] $mmm41 = StringSplit($mmm40, "H") $mmm42 = $mmm41[2] $mmm43 = $EREZ[$k + 8] $mmm44 = StringSplit($mmm43, "H") $mmm45 = $mmm44[2] $mmm50 = $EREZ[$k + 11] $mmm51 = StringSplit($mmm50, "H") $mmm52 = $mmm51[2] $mmm53 = $EREZ[$k + 12] $mmm54 = StringSplit($mmm53, "H") $mmm55 = $mmm54[2] $k = _ArraySearch($EREZ, "AGENT NAME", 0, 0, 1, 1) $H = GUICreate("Monitoring...", 400, 400, 100, 100) $H1 = GUICtrlCreateLabel($mmm3, 100, 20) $H2 = GUICtrlCreateLabel($mmm13 & " " & $mmm16, 15, 50) $H3 = GUICtrlCreateLabel($mmm22 & " " & $mmm25, 240, 50) $H4 = GUICtrlCreateLabel($mmm32 & " " & $mmm35, 15, 90) $H5 = GUICtrlCreateLabel($mmm42 & " " & $mmm45, 240, 90) $H6 = GUICtrlCreateLabel($mmm52 & " " & $mmm55, 240, 110) $p = 170 For $i = 1 To 12 $agent0 = $EREZ[$k + 1] ;if @error then ExitLoop $agent1 = StringSplit($agent0, "H") If @error Then ExitLoop $agent2 = $agent1[2] $agent3 = $EREZ[$k + 2] $agent4 = StringSplit($agent3, "H") If @error Then ExitLoop $agent5 = $agent4[2] $agent6 = $EREZ[$k + 3] $agent7 = StringSplit($agent6, "H") If @error Then ExitLoop $agent8 = $agent7[2] $agent9 = $EREZ[$k + 4] $agent10 = StringSplit($agent9, "H") If @error Then ExitLoop $agent11 = $agent10[2] $H7[$i] = GUICtrlCreateLabel($agent2, 25, $p) $H8[$i] = GUICtrlCreateLabel($agent5 & " " & $agent8 & " " & $agent11, 150, $p) ;MsgBox (0,"done!","") $p = $p + 20 $k = $k + 8 Next MsgBox(0, "this is $i and $p", $i & " " & $p) For $o = $i To (12 - $i) $H7[$o] = GUICtrlCreateLabel(" ", 25, $p) $H8[$o] = GUICtrlCreateLabel(" ", 150, $p) $p = $p + 20 Next _ArrayDisplay($H7) _ArrayDisplay($H8) GUISetState() $msg = GUIGetMsg() FileDelete("c:\erez.txt") FileDelete("c:\erez1.txt") Sleep(10000) TCPSend($ConnectedSocket, "0x1b78") Sleep(200) TCPSend($ConnectedSocket, $a) Sleep(100) 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) $j = FileOpen("c:\erez.txt", 2) FileWrite("c:\erez.txt", $m) FileWrite("c:\erez.txt", $n) FileWrite("c:\erez.txt", $r) FileClose($j) EndFunc ;==>erez2 Func erez3() While 1 Local $EREZ[500] $FileOrig = "c:\erez.txt" $sfileread = FileRead($FileOrig) $sfileread = StringReplace($sfileread, Chr(0), "") ;$sfileread = StringReplace($sfileread, Chr(13), "") $FileResult = "c:\erez1.txt" $hFile = FileOpen($FileResult, 2) FileWrite($hFile, $sfileread) FileClose($hFile) $Read = FileRead("c:\erez.txt") $Replace = StringReplace($Read, "", "") $Replace = StringReplace($Replace, Chr("7f"), "") $EREZ = StringSplit($Replace, "[") ; _ArrayDisplay($EREZ) $k = _ArraySearch($EREZ, "BCMS SKILL (AGENT) STATUS", 0, 0, 1, 1) ;MsgBox(0, "this is where $k is:", $k) $mmm1 = $EREZ[$k] $mmm2 = StringSplit($mmm1, "H") $mmm3 = $mmm2[2] $mmm11 = $EREZ[$k + 1] $mmm12 = StringSplit($mmm11, "H") $mmm13 = $mmm12[2] $mmm14 = $EREZ[$k + 2] $mmm15 = StringSplit($mmm14, "H") $mmm16 = $mmm15[2] $mmm20 = $EREZ[$k + 3] $mmm21 = StringSplit($mmm20, "H") $mmm22 = $mmm21[2] $mmm23 = $EREZ[$k + 4] $mmm24 = StringSplit($mmm23, "H") $mmm25 = $mmm24[2] $mmm30 = $EREZ[$k + 5] $mmm31 = StringSplit($mmm30, "H") $mmm32 = $mmm31[2] $mmm33 = $EREZ[$k + 6] $mmm34 = StringSplit($mmm33, "H") $mmm35 = $mmm34[2] $mmm40 = $EREZ[$k + 7] $mmm41 = StringSplit($mmm40, "H") $mmm42 = $mmm41[2] $mmm43 = $EREZ[$k + 8] $mmm44 = StringSplit($mmm43, "H") $mmm45 = $mmm44[2] $mmm50 = $EREZ[$k + 11] $mmm51 = StringSplit($mmm50, "H") $mmm52 = $mmm51[2] $mmm53 = $EREZ[$k + 12] $mmm54 = StringSplit($mmm53, "H") $mmm55 = $mmm54[2] $k = _ArraySearch($EREZ, "AGENT NAME", 0, 0, 1, 1) ;$H = GUICreate("Monitoring...", 400, 400, 100, 100) ;$H1 = GUICtrlCreateLabel($mmm3, 100, 20) ;$H2 = GUICtrlCreateLabel($mmm13 & " " & $mmm16, 15, 50) ;$H3 = GUICtrlCreateLabel($mmm22 & " " & $mmm25, 240, 50) ;$H4 = GUICtrlCreateLabel($mmm32 & " " & $mmm35, 15, 90) ;$H5 = GUICtrlCreateLabel($mmm42 & " " & $mmm45, 240, 90) ;$H6 = GUICtrlCreateLabel($mmm52 & " " & $mmm55, 240, 110) $p = 170 For $i = 1 To 12 $agent0 = $EREZ[$k + 1] ;if @error then ExitLoop $agent1 = StringSplit($agent0, "H") If @error Then ExitLoop $agent2 = $agent1[2] $agent3 = $EREZ[$k + 2] $agent4 = StringSplit($agent3, "H") If @error Then ExitLoop $agent5 = $agent4[2] $agent6 = $EREZ[$k + 3] $agent7 = StringSplit($agent6, "H") If @error Then ExitLoop $agent8 = $agent7[2] $agent9 = $EREZ[$k + 4] $agent10 = StringSplit($agent9, "H") If @error Then ExitLoop $agent11 = $agent10[2] GUICtrlSetData($H7[$i], $agent2) GUICtrlSetData($H8[$i], $agent5 & " " & $agent8 & " " & $agent11) ; MsgBox (0,"done!","") $p = $p + 20 $k = $k + 8 Next MsgBox(0, "this is $i", $i) For $o = $i To (12 - $i) $H7[$o] = GUICtrlCreateLabel(" ", 25, $p) $H8[$o] = GUICtrlCreateLabel(" ", 150, $p) $p = $p + 20 Next GUISetState() $msg = GUIGetMsg() FileDelete("c:\erez.txt") FileDelete("c:\erez1.txt") Sleep(10000) TCPSend($ConnectedSocket, "0x1b78") Sleep(200) TCPSend($ConnectedSocket, $a) Sleep(100) 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) $j = FileOpen("c:\erez.txt", 2) FileWrite("c:\erez.txt", $m) FileWrite("c:\erez.txt", $n) FileWrite("c:\erez.txt", $r) FileClose($j) If $msg = $GUI_EVENT_CLOSE Then Exit WEnd EndFunc ;==>erez3 but still this: If $msg = $GUI_EVENT_CLOSE Then Exit MsgBox (0,"this is $msg",$msg) isn't working, why doesn't it remember that I'v pressed "X" to close the window? I'v put $msg on global var! I don't get it! Edited February 8, 2008 by erezlevi Link to comment Share on other sites More sharing options...
PsaltyDS Posted February 8, 2008 Share Posted February 8, 2008 None of the functions are calling themselves anymore, so there should be no recursion issues. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
erezlevi Posted February 8, 2008 Author Share Posted February 8, 2008 None of the functions are calling themselves anymore, so there should be no recursion issues. what do you think about the second part, should I use Do ---> Until instead of IF to close the application? with If $msg=$GUI_EVENT_CLOSE isn't working. Link to comment Share on other sites More sharing options...
PsaltyDS Posted February 8, 2008 Share Posted February 8, 2008 what do you think about the second part, should I use Do ---> Until instead of IF to close the application? with If $msg=$GUI_EVENT_CLOSE isn't working.You have 15.3sec of Sleep() plus all those other execution times between GuiGetMsg() and finally testing it with "If $msg =". You don't want your GuiGetMsg() loop to be anywhere near that long.Personally, I would dump that entirely for GuiOnEventMode. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
erezlevi Posted February 8, 2008 Author Share Posted February 8, 2008 You have 15.3sec of Sleep() plus all those other execution times between GuiGetMsg() and finally testing it with "If $msg =". You don't want your GuiGetMsg() loop to be anywhere near that long.Personally, I would dump that entirely for GuiOnEventMode. Thanks, you solved it!here I used this:Opt("GUIOnEventMode", 1) and then under the GUI creation this:GUISetOnEvent ($GUI_EVENT_CLOSE,"close")and a function "close" to close it. Thanks, you saved my script. 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