Jump to content
Sign in to follow this  
supraaxdd

Error Code 0 appears all the time?

Recommended Posts

Hello!

I have a problem where I am trying to create a basic internet connection test (for myself) and will not be disctributed, so some code will be formed of local functions and repeated functions etc.

Whenever I start up the script and go through the process of picking the region (Only Europe works), it will connect but at the end it will pop an error code 0. I don't know how to get rid of it. Thanks for the help in advance!

 

Internet Testesr.au3

Share this post


Link to post
Share on other sites

Hello!

I have a problem where I am trying to create a basic internet connection test (for myself) and will not be disctributed, so some code will be formed of local functions and repeated functions etc.

Whenever I start up the script and go through the process of picking the region (Only Europe works), it will connect but at the end it will pop an error code 0. I don't know how to get rid of it. Thanks for the help in advance!

Internet Testesr.au3

Share this post


Link to post
Share on other sites

It would be the following if statement, which is implying that the ping is less than the ping limit aka 150ms

If $iPingEU > $PingLimit Then
    MsgBox(0, "Warning", "Your internet connection is unstable!")
Else
    MsgBox(0,"","An error occurred. Error Code: " & @error)
EndIf

 

Share this post


Link to post
Share on other sites
18 minutes ago, Jos said:

@supraaxdd,

Please do not cross-post topics in multiple forums ( and wrong) forums!

Jos

Sorry Jos! Im new to all of this and may not know where everything goes. Will do it properly next time

Kind Regards,

Supra

Share this post


Link to post
Share on other sites
16 hours ago, Subz said:

It would be the following if statement, which is implying that the ping is less than the ping limit aka 150ms

If $iPingEU > $PingLimit Then
    MsgBox(0, "Warning", "Your internet connection is unstable!")
Else
    MsgBox(0,"","An error occurred. Error Code: " & @error)
EndIf

 

I swapped the ">" for a "<" and it said the "Your internet is unstable" MsgBox and no error code. I don't want that to happen. Would I have to say if the $iPingEU is not < $PingLimit to fix the code and if so, is there an operator for that which I doubt there is or a certain method that I have to use?

 

Kind Regards,

Supra

Share this post


Link to post
Share on other sites

Try something like:

#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)
GUICtrlCreateGroup("", -1, -1, 1, 1)
$ButtonYes = GUICtrlCreateButton("&Yes", 230, 160, 75, 25)
$ButtonCan = GUICtrlCreateButton("&Cancel", 310, 160, 75, 25)
GUISetState(@SW_SHOW)
$GUI2 = GUICreate("Which Region?", 400, 200, -1, -1)
$ButtonEU = GUICtrlCreateButton("Europe", 20, 20, 80, 30)
$ButtonNA = GUICtrlCreateButton("North America", 120, 20, 80, 30)
$ButtonAU = GUICtrlCreateButton("Australia", 220, 20, 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, $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)
        Case $ButtonEU
            _PingFunc("google.ie")
        Case $ButtonNA
            _PingFunc("192.0.43.10")
        Case $ButtonAU
            _PingFunc("192.0.43.10")
        Case $ButtonCan
            Exit
    EndSwitch
WEnd

Func _PingFunc($vPing, $iPingLimit = 150)
    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", $vPing & ": Host is offline.")
            Case 2
                MsgBox(4096, "Error", $vPing & ": Host is unreachable")
            Case 3
                MsgBox(4096, "Error", $vPing & ": Bad destination")
            Case 4
                MsgBox(4096, "Error", $vPing & ": Other errors")
        EndSwitch
        Return
    EndIf
    If $iPing >= $iPingLimit Then
        MsgBox(4096, "Warning", "Your internet connection is unstable!" & @CRLF & "Internet connection speed: " & $iPing & "ms.")
    Else
        MsgBox(4096, "SpeedTest", "Your internet connection is: " & $iPing & "ms.")
    EndIf
    GUISetState(@SW_HIDE, $GUIConnecting)
    GUISetState(@SW_HIDE, $LabelConn)
EndFunc

 

Share this post


Link to post
Share on other sites
On 3/5/2019 at 9:09 PM, Subz said:

Try something like:

#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)
GUICtrlCreateGroup("", -1, -1, 1, 1)
$ButtonYes = GUICtrlCreateButton("&Yes", 230, 160, 75, 25)
$ButtonCan = GUICtrlCreateButton("&Cancel", 310, 160, 75, 25)
GUISetState(@SW_SHOW)
$GUI2 = GUICreate("Which Region?", 400, 200, -1, -1)
$ButtonEU = GUICtrlCreateButton("Europe", 20, 20, 80, 30)
$ButtonNA = GUICtrlCreateButton("North America", 120, 20, 80, 30)
$ButtonAU = GUICtrlCreateButton("Australia", 220, 20, 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, $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)
        Case $ButtonEU
            _PingFunc("google.ie")
        Case $ButtonNA
            _PingFunc("192.0.43.10")
        Case $ButtonAU
            _PingFunc("192.0.43.10")
        Case $ButtonCan
            Exit
    EndSwitch
WEnd

Func _PingFunc($vPing, $iPingLimit = 150)
    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", $vPing & ": Host is offline.")
            Case 2
                MsgBox(4096, "Error", $vPing & ": Host is unreachable")
            Case 3
                MsgBox(4096, "Error", $vPing & ": Bad destination")
            Case 4
                MsgBox(4096, "Error", $vPing & ": Other errors")
        EndSwitch
        Return
    EndIf
    If $iPing >= $iPingLimit Then
        MsgBox(4096, "Warning", "Your internet connection is unstable!" & @CRLF & "Internet connection speed: " & $iPing & "ms.")
    Else
        MsgBox(4096, "SpeedTest", "Your internet connection is: " & $iPing & "ms.")
    EndIf
    GUISetState(@SW_HIDE, $GUIConnecting)
    GUISetState(@SW_HIDE, $LabelConn)
EndFunc

 

I ran this code an it worked, Thanks so much!

May I ask, how you defined $vPing? Are you able to define it in the Func name? I read the Helpfile and didn't really understand it.

Kind Regards,
Supra

Edit:

Don't answer the $vPing question. I understand how it works. Thanks for helping me anyways :)

 

Edited by supraaxdd

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...