Jump to content

Second GUI doesn't close despite of there being a case to close it


 Share

Recommended Posts

Hello.

I am a fairly new scripter to this language but know some tricks or some terms used.

I have a problem with the update log closing despite of there being a case for the close button. It may be the second GUISetState to @SW_SHOW telling the Update Log to start up too. I tried disabling and enabling it, nothing works. I have no idea how to fix it and I sat for a while thinking how and I ran out of ideas. I know that there are excellent experts within this community and I believe that this community can help me yet again. Here is the script:

 

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$MainGUI = GUICreate("Internet Test", 400, 200, -1, -1)
$GroupBox1 = GUICtrlCreateLabel("Do you want to start testing your internet connection on your device?", 40, 50, 400, 20)
$AusWarn = GUICtrlCreateLabel("Note: Australia, South America and South Africa will not always" & @CRLF & "be pinged due to an unsteady connection.", 40, 80, 400, 40)
GUICtrlCreateGroup("", -1, -1, 1, 1)
$ButtonYes = GUICtrlCreateButton("&Yes", 230, 160, 75, 25)
$ButtonCan = GUICtrlCreateButton("&Cancel", 310, 160, 75, 25)
$ButtonUpL = GUICtrlCreateButton("Update Log", 10, 160, 75, 25)
GUISetState(@SW_SHOW)
$UpdGUI = GUICreate("Update Log", 400, 600, -1, -1)
$UpdGUILabel = GUICtrlCreateLabel("Update Log for v1.0.1:" & @CR & @CR & "- Changed the Australian IP for better connections." & @CR &  "- Displays the IP/Website the tool pinged" & @CR & @CR & @CR & "Update Log for v1.0.2" & @CR & @CR & "- Displays the IP/Website the tool pinged" & @CR & "- Added support for Middle East, South Africa, Asia and South America" & @CR & @CR & @CR & "Update Log for v1.0.3" & @CR & @CR & "- Added the Update Log" & @CR & "- Edited the note saying that some more regions may be buggy." & @CR & "", 40, 30, 400, 600)
$ButtonCloseUpd = GUICtrlCreateButton("Close", 175, 560, 75, 25)
GUISetState(@SW_SHOW)
;~ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
$GUI2 = GUICreate("Which Region?", 400, 200, -1, -1)
$ButtonEU = GUICtrlCreateButton("Europe", 10, 20, 80, 30)
$ButtonNA = GUICtrlCreateButton("North America", 110, 20, 80, 30)
$ButtonAU = GUICtrlCreateButton("Australia", 210, 20, 80, 30)
$ButtonAS = GUICtrlCreateButton("Asia", 310, 20, 80, 30)
$ButtonSA = GUICtrlCreateButton("South America", 10, 60, 80, 30)
$ButtonAF = GUICtrlCreateButton("South Africa", 110, 60, 80, 30)
$ButtonME = GUICtrlCreateButton("Middle East", 210, 60, 80, 30)
$GUIConnecting = GUICreate("Connecting...",200,100,-1,-1)
$LabelConn = GUICtrlCreateLabel("Connecting..." ,40, 50, 400, 20)
GUISetState(@SW_HIDE, $GUI2)
GUISetState(@SW_HIDE, $ButtonEU)
GUISetState(@SW_HIDE, $ButtonNA)
GUISetState(@SW_HIDE, $ButtonAU)
GUISetState(@SW_HIDE, $ButtonAS)
GUISetState(@SW_HIDE, $ButtonAF)
GUISetState(@SW_HIDE, $ButtonME)
GUISetState(@SW_HIDE, $GUIConnecting)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg

         Case $GUI_EVENT_CLOSE
            Exit

         Case $ButtonYes
            GUISetState(@SW_SHOW, $GUI2)
            GUISetState(@SW_SHOW, $ButtonEU)
            GUISetState(@SW_SHOW, $ButtonNA)
            GUISetState(@SW_SHOW, $ButtonAU)
            GUISetState(@SW_SHOW, $ButtonAS)
            GUISetState(@SW_SHOW, $ButtonAF)
            GUISetState(@SW_SHOW, $ButtonME)

         Case $ButtonUpL
            GUISetState(@SW_SHOW, $UpdGUI)

         Case $ButtonCloseUpd
            GUISetState(@SW_HIDE, $UpdGUI)

         Case $ButtonEU
            _PingFunc("google.ie")

         Case $ButtonNA
            _PingFunc("192.0.43.10")

         Case $ButtonAU
            _PingFunc("101.0.86.43")

         Case $ButtonAS
            _PingFunc("47.94.129.116")

         Case $ButtonSA
            _PingFunc("131.255.7.26")

         Case $ButtonAF
            _PingFunc("197.221.23.194")

         Case $ButtonME
            _PingFunc("185.229.226.83")

         Case $ButtonCan
            Exit
    EndSwitch
WEnd

Func _PingFunc($vPing, $iPingLimit = 250)
    GUISetState(@SW_SHOW, $GUIConnecting)
    GUISetState(@SW_SHOW, $LabelConn)
    Sleep(3000)
    Local $iPing = Ping($vPing, 250)
    If @error Then
        Switch @error
            Case 1
                MsgBox(4096, "Error","Host is offline.")

            Case 2
                MsgBox(4096, "Error","Host is unreachable")

            Case 3
                MsgBox(4096, "Error","Bad destination")

            Case 4
                MsgBox(4096, "Error","Other errors")

        EndSwitch
        Return
    EndIf
    If $iPing >= $iPingLimit Then
        MsgBox(4096, "Warning", "Your internet connection is unstable!" & @CRLF & "Internet connection speed: " & $iPing & "ms.")
        Msgbox(0,"SpeedTest","The IP/Website you connected to was: " & $vPing)
    Else
        MsgBox(4096, "SpeedTest", "Your internet connection is: " & $iPing & "ms.")
        Msgbox(0,"SpeedTest", "The IP/Website you connected to was: " & $vPing)
    EndIf
    GUISetState(@SW_HIDE, $GUIConnecting)
    GUISetState(@SW_HIDE, $LabelConn)
EndFunc

Yet again, I would like to thank everyone that contributes to helping me with this issue

Kind Regards,

Supra.

Link to comment
Share on other sites

1 hour ago, user4157124 said:

Use GUIGetMsg() like GUIGetMsg($GUI_EVENT_ARRAY) so it returns an array; $aArray[0] contains event-/control ID and $aArray[1] window handle the event is from. Enables distinction between multiple GUI's.

https://www.autoitscript.com/autoit3/docs/functions/GUIGetMsg.htm

It sounds complicated as hell because I  was working on work experience and I was working with Arrays. Believe me: Me + Arrays = are a bad thing but thanks for the reply!

Kind Regards,

Supra

Link to comment
Share on other sites

13 minutes ago, supraaxdd said:

I think that as days go by, I'm getting dumber and dumber...

Thanks so much :D

Nah, it is a common error not easy to find when you haven't gone though this before, now you know :bye:

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

×
×
  • Create New...