Jump to content

what is wrong with this finction ?


dirty
 Share

Recommended Posts

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

Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

*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

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

Link to comment
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!"

Link to comment
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

Link to comment
Share on other sites

$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
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...