Jump to content
Sign in to follow this  
saverfixer

Need help: Cant terminate

Recommended Posts

saverfixer

#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

Share this post


Link to post
Share on other sites
BrettF

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 by BrettF

Share this post


Link to post
Share on other sites
Skruge

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]

Share this post


Link to post
Share on other sites
saverfixer

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

Share this post


Link to post
Share on other sites
PsaltyDS

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

Skruge 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

Share this post


Link to post
Share on other sites
saverfixer

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

Share this post


Link to post
Share on other sites
BrettF
saverfixer

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 by saverfixer

Share this post


Link to post
Share on other sites
Skruge

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.

#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 by Skruge

[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

Share this post


Link to post
Share on other sites
saverfixer

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 by saverfixer

Share this post


Link to post
Share on other sites
nekkutta

Here you go, notice the Global $bWriteLog after the Gui descriptors that will control if it write to file or not

#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]

Share this post


Link to post
Share on other sites
Skruge

: 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]

Share this post


Link to post
Share on other sites
saverfixer

Thanks it works.

Ill rewrite it to better understand what was changed and how it works

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  

×