Sign in to follow this  
Followers 0
dirty

what is wrong with this finction ?

6 posts in this topic

While 1
    $ping = Ping ("http://www.google.com")
        If @error = 0 Then
        MsgBox (16,'Error',"Host is not pingable or other network errors occurred",1000)
    ElseIf @error = 1 Then
        MsgBox (16,'Error',"Host is offline",1000)
    ElseIf @error = 2 Then
        MsgBox (16,'Error',"Host is unreachable",1000)
    ElseIf @error = 3 Then
        MsgBox (16,'Error',"Bad destination",1000)
    ElseIf @error = 4 Then
        MsgBox (16,'Error',"Other connection errors",1000)
    ElseIf $ping > 0 Then
        MsgBox (32,"Success","Return in " & Round ($ping) & "ms")
    EndIf
WEnd

i know my computer is connected, yet i get error based on this script.

Am i reading errors the wrong way ?

Can you clear this out for me ? Am not sure if i read the errors right.

Thanks in advance

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

The first comparison is wrong. @error = 0 denotes a succesful PING not an error. Use:

While 1
    $ping = Ping ("http://www.google.com")
    If @error = 0 Then
        MsgBox (32,"Success","Return in " & Round ($ping) & "ms")
    ElseIf @error = 1 Then
        MsgBox (16,'Error',"Host is offline",1000)
    ElseIf @error = 2 Then
        MsgBox (16,'Error',"Host is unreachable",1000)
    ElseIf @error = 3 Then
        MsgBox (16,'Error',"Bad destination",1000)
    ElseIf @error = 4 Then
        MsgBox (16,'Error',"Other connection errors",1000)
    Else
        MsgBox (16,"Error","Unknown error occurred: " & @error)
    EndIf
WEnd

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

*what water said

While 1
    $ping = Ping ("www.google.com" , 4000)
 
        If @error Then
    ElseIf @error = 1 Then
        MsgBox (16,'Error',"Host is offline",1000)
    ElseIf @error = 2 Then
        MsgBox (16,'Error',"Host is unreachable",1000)
    ElseIf @error = 3 Then
        MsgBox (16,'Error',"Bad destination",1000)
    ElseIf @error = 4 Then
        MsgBox (16,'Error',"Other connection errors",1000)
    ElseIf $ping > 0 Then
        MsgBox (32,"Success","Return in " & Round ($ping) & "ms")
    EndIf
 
    exit
 
 
WEnd
Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

take the http:// out of the ping call. Also, take out the If @Error = 0 condition. @Error will be 0 if Ping worked properly. And you probably don't want it in a loop unless you do something to exit the loop. Otherwise good luck with trying to do anything.

;While 1
    $ping = Ping ("www.google.com")
        ;If @error = 0 Then
        ;MsgBox (16,'Error',"Host is not pingable or other network errors occurred",1000)
   If @error = 1 Then
        MsgBox (16,'Error',"Host is offline",1000)
    ElseIf @error = 2 Then
        MsgBox (16,'Error',"Host is unreachable",1000)
    ElseIf @error = 3 Then
        MsgBox (16,'Error',"Bad destination",1000)
    ElseIf @error = 4 Then
        MsgBox (16,'Error',"Other connection errors",1000)
    ElseIf $ping > 0 Then
        MsgBox (32,"Success","Return in " & Round ($ping) & "ms")
    EndIf
;WEnd

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

I thought according to help file Failure: Returns 0

so i thought 0 would be @Error = 0

LOL

Is there another way to read the error produced by $Ping variable ?

Maybe

$Ping = ("google.com")

$Error = @error

If $Error = 0 then .......etc

would this be a good way if doing it ?

This way i can check for @error value later in the script instead of checking it right after the ping() function

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

$Kontrolli_jaamu = Ping("194.106.119.243", 100)
   Switch @error
    Case 0
      $Viga = "All OK"
    Case 1
      $Viga = "Host is offline"
    Case 2
      $Viga = "Host is unreachable"
    Case 3
      $Viga = "Bad destination"
    Case 4
      $Viga = "Other errors"
   EndSwitch

edit:wtf happens to layout??

Edited by shaqan

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  
Followers 0