saverfixer Posted July 3, 2009 Share Posted July 3, 2009 expandcollapse popup#Region;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_icon=shell32_257.ico #AutoIt3Wrapper_Compression=4 #AutoIt3Wrapper_Res_Fileversion=1.3 #EndRegion;**** Directives created by AutoIt3Wrapper_GUI **** #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> GUICreate("", 400, 120) GUISetState(@SW_SHOW) GUICtrlCreateLabel ("made by: SaverFixer",300,103) $log = GUICtrlCreateEdit('', 100, 0, 300, 100) $Addressinput = GUICtrlCreateInput("google.com", 0, 0, 100, 20) $Addressinput2 = GUICtrlCreateInput("yahoo.com", 0, 20, 100, 20) $Timeinput = GUICtrlCreateInput("15000", 0, 40, 40, 20) GUICtrlCreateLabel("1000=1sec", 40, 43, 60) $Button = GUICtrlCreateButton("Poke'em", 0, 60, 100, 40) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $Button While 1 $Address = GUICtrlRead($Addressinput) $Time = GUICtrlRead($Timeinput) $ping = Ping($Address) $writelog = GUICtrlSetData($log, 'Server response in '& $ping & ' ms'& @CRLF) GUICtrlSetLimit($writelog,10) Sleep ($Time) If $ping = 0 Then GUICtrlSetData($log, @MDAY & " " & @MON & " " & @YEAR & " No response from " & $Address & " at" & @HOUR & ':' & @MIN & @CRLF) ;$output = GUICtrlRead($log) ;FileWrite("Log.txt", $output) Sleep ($Time) ; Try second server $Address2 = GUICtrlRead($Addressinput2) $ping2 = Ping($Address2) If $ping2 = 0 Then GUICtrlSetData($log, @MDAY & " " & @MON & " " & @YEAR & " Both servers did not respond at " & @HOUR & ':' & @MIN & @CRLF) $output2 = GUICtrlRead($log) FileWrite("Log.txt", $output2) Sleep ($Time) EndIf EndIf WEnd Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Exit This program wont exit if i press X on top corner. I tried adding new Case for new button to do the Exit command but that didnt work aether Can you guys help me with the exit thingy? ESC key shortcut worked but i dont want to use that, i want to have a button that does that. Thanks in advance Link to comment Share on other sites More sharing options...
BrettF Posted July 3, 2009 Share Posted July 3, 2009 (edited) Where do you tell it to exit when you press that button? In your main GUI Message loop you must have a Case for $GUI_EVENT_CLOSE (-3) for it to do anything. I hope you know what to put in that case statement Cheers, Brett Also, you never exit the second loop with Case $Button1. Whats the point of Exit at the end? What else will the script do? Sit around drinking a cup of coffee? Edited July 3, 2009 by BrettF Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
Skruge Posted July 3, 2009 Share Posted July 3, 2009 Clicking the Close button, hitting Escape, or F4 all work to exit the script. The problem is, the "Poke'em" button causes and endless loop and all further messages are lost. The button should toggle a flag that causes the main loop or an adlib function to do the pinging. This way, message processing can continue as normal. [font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font] Link to comment Share on other sites More sharing options...
saverfixer Posted July 3, 2009 Author Share Posted July 3, 2009 ok skruge so how do i fix it ? Yes i want to create another button that will exit $exit = guictlrcreatebutton ("exit", "coordinates") Case $exit exit thats it but its not working. I understand there is a loop but i dont know how to terminate it with exit button Link to comment Share on other sites More sharing options...
PsaltyDS Posted July 4, 2009 Share Posted July 4, 2009 ok skruge so how do i fix it ?Yes i want to create another button that will exit $exit = guictlrcreatebutton ("exit", "coordinates")Case $exitexitthats it but its not working.I understand there is a loop but i dont know how to terminate it with exit buttonSkruge is telling you that you need to fix the While/WEnd loop under "Case $Button" so it exits and returns to the outer While/WEnd GuiGetMsg() loop.Alternatively, you could recode for GuiOnEventMode instead of message mode. 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...
saverfixer Posted July 4, 2009 Author Share Posted July 4, 2009 i wish it was as easy as you say but i dont know much about loops. Dam i dont know much about autoit its self . Can you give me an example or something ? THanks Link to comment Share on other sites More sharing options...
BrettF Posted July 4, 2009 Share Posted July 4, 2009 Why does it need to loop in the first place? Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
saverfixer Posted July 4, 2009 Author Share Posted July 4, 2009 (edited) i dont know, so it would keep pinging those servers and never stop ? I have no idea why and how it works even if i made it my self I made this for my server to track if network provider disconnects me for some reasons. Program logs date and time when both servers did not respond and writing it into LOG so i will have date and time to refer as network drop. I had that idea when Comcast tech came over and did ping test on google (i was like WOW i gotta use that somehow) Edited July 4, 2009 by saverfixer Link to comment Share on other sites More sharing options...
Skruge Posted July 7, 2009 Share Posted July 7, 2009 (edited) I wrote something similar a few years ago, and needed it today. (DSL issues) The source code is at work, so I just rewrote yours. expandcollapse popup#Region;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=shell32_257.ico #AutoIt3Wrapper_Compression=4 #AutoIt3Wrapper_Res_Fileversion=1.3 #EndRegion;**** Directives created by AutoIt3Wrapper_GUI **** #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> GUICreate("", 400, 120) GUISetState(@SW_SHOW) GUICtrlCreateLabel("made by: SaverFixer", 300, 103) Global $log = GUICtrlCreateEdit('', 100, 0, 300, 100) Global $Addressinput = GUICtrlCreateInput("google.com", 0, 0, 100, 20) Global $Addressinput2 = GUICtrlCreateInput("yahoo.com", 0, 20, 100, 20) Global $Timeinput = GUICtrlCreateInput("15", 0, 40, 40, 20) GUICtrlCreateLabel("Seconds", 40, 43, 60) Global $Button = GUICtrlCreateButton("Poke'em", 0, 60, 100, 40) Global $bPingActive = False While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $Button If $bPingActive Then GUICtrlSetData($Button, "Poke'em") GUICtrlSetState($Addressinput, $GUI_ENABLE) GUICtrlSetState($Addressinput2, $GUI_ENABLE) GUICtrlSetState($Timeinput, $GUI_ENABLE) GUICtrlSetState($log, $GUI_ENABLE) AdlibDisable() Else GUICtrlSetData($Button, "STOP") GUICtrlSetState($Addressinput, $GUI_DISABLE) GUICtrlSetState($Addressinput2, $GUI_DISABLE) GUICtrlSetState($Timeinput, $GUI_DISABLE) GUICtrlSetState($log, $GUI_DISABLE) $Address = GUICtrlRead($Addressinput) $Address2 = GUICtrlRead($Addressinput2) $Time = GUICtrlRead($Timeinput) * 1000 _PingServers() AdlibEnable("_PingServers", $Time) EndIf $bPingActive = Not $bPingActive Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _PingServers() Local $ping = Ping($Address) If @error Then _LogIt("No response from " & $Address) $ping = Ping($Address2) If @error Then _LogIt("Both servers did not respond.", True) Else _LogIt($Address2 & ' responded in ' & $ping & ' ms') EndIf Else _LogIt($Address & ' responded in ' & $ping & ' ms') EndIf EndFunc ;==>_PingServers Func _LogIt($sString, $bWriteLog = False) Local $output = StringFormat("%04d/%02d/%02d %02d:%02d:%02d : %s\r\n", @YEAR, @MON, @MDAY, @HOUR, @MIN, @SEC, $sString) GUICtrlSetData($log, $output, "UPDATE") If $bWriteLog Then FileWrite("Log.txt", $output) EndFunc ;==>_LogIt@Edit: Added optional parameter value. Edited July 8, 2009 by Skruge [font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font] Link to comment Share on other sites More sharing options...
saverfixer Posted July 8, 2009 Author Share Posted July 8, 2009 (edited) wow thanks allot man but somehow it dont work. : ERROR: _LogIt() called by a previous line with 1 arg(s). Min = 2. First previous line calling this Func is 55. Func _LogIt($sString, $bWriteLog) If i continue anyway it will exit as soon as i press pokem Edited July 8, 2009 by saverfixer Link to comment Share on other sites More sharing options...
nekkutta Posted July 8, 2009 Share Posted July 8, 2009 Here you go, notice the Global $bWriteLog after the Gui descriptors that will control if it write to file or not expandcollapse popup#Region;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=shell32_257.ico #AutoIt3Wrapper_Compression=4 #AutoIt3Wrapper_Res_Fileversion=1.3 #EndRegion;**** Directives created by AutoIt3Wrapper_GUI **** #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> GUICreate("", 400, 120) GUISetState(@SW_SHOW) GUICtrlCreateLabel("made by: SaverFixer", 300, 103) Global $log = GUICtrlCreateEdit('', 100, 0, 300, 100) Global $Addressinput = GUICtrlCreateInput("google.com", 0, 0, 100, 20) Global $Addressinput2 = GUICtrlCreateInput("yahoo.com", 0, 20, 100, 20) Global $Timeinput = GUICtrlCreateInput("15", 0, 40, 40, 20) GUICtrlCreateLabel("Seconds", 40, 43, 60) Global $Button = GUICtrlCreateButton("Poke'em", 0, 60, 100, 40) Global $bPingActive = False Global $bWriteLog = True While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $Button If $bPingActive Then GUICtrlSetData($Button, "Poke'em") GUICtrlSetState($Addressinput, $GUI_ENABLE) GUICtrlSetState($Addressinput2, $GUI_ENABLE) GUICtrlSetState($Timeinput, $GUI_ENABLE) GUICtrlSetState($log, $GUI_ENABLE) AdlibDisable() Else GUICtrlSetData($Button, "STOP") GUICtrlSetState($Addressinput, $GUI_DISABLE) GUICtrlSetState($Addressinput2, $GUI_DISABLE) GUICtrlSetState($Timeinput, $GUI_DISABLE) GUICtrlSetState($log, $GUI_DISABLE) $Address = GUICtrlRead($Addressinput) $Address2 = GUICtrlRead($Addressinput2) $Time = GUICtrlRead($Timeinput) * 1000 _PingServers() AdlibEnable("_PingServers", $Time) EndIf $bPingActive = Not $bPingActive Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _PingServers() Local $ping = Ping($Address) If @error Then _LogIt("No response from " & $Address) $ping = Ping($Address2) If @error Then _LogIt("Both servers did not respond.", True) Else _LogIt($Address2 & ' responded in ' & $ping & ' ms') EndIf Else _LogIt($Address & ' responded in ' & $ping & ' ms') EndIf EndFunc ;==>_PingServers Func _LogIt($sString) Local $output = StringFormat("%04d/%02d/%02d %02d:%02d:%02d : %s\r\n", @YEAR, @MON, @MDAY, @HOUR, @MIN, @SEC, $sString) GUICtrlSetData($log, $output, "UPDATE") If $bWriteLog Then FileWrite("Log.txt", $output) EndFunc ;==>_LogIt [size="2"] "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." - Brian Kernighan[/size] Link to comment Share on other sites More sharing options...
Skruge Posted July 8, 2009 Share Posted July 8, 2009 : ERROR: _LogIt() called by a previous line with 1 arg(s). Min = 2. First previous line calling this Func is 55.That's what I get for not testing... It's an optional parameter. Func _LogIt($sString, $bWriteLog = False) Local $output = StringFormat("%04d/%02d/%02d %02d:%02d:%02d : %s\r\n", @YEAR, @MON, @MDAY, @HOUR, @MIN, @SEC, $sString) GUICtrlSetData($log, $output, "UPDATE") If $bWriteLog Then FileWrite("Log.txt", $output) EndFunc ;==>_LogIt [font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font] Link to comment Share on other sites More sharing options...
saverfixer Posted July 8, 2009 Author Share Posted July 8, 2009 Thanks it works. Ill rewrite it to better understand what was changed and how it works 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