dirty 0 Posted October 11, 2011 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
water 2,387 Posted October 11, 2011 (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 October 11, 2011 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX (NEW 2020-12-15 - Version 1.6.3.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2020-06-27 - Version 1.3.2.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - WikiTask Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - WikiTutorials:ADO - Wiki, WebDriver - Wiki Share this post Link to post Share on other sites
iamtheky 927 Posted October 11, 2011 (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 October 11, 2011 by boththose ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Share this post Link to post Share on other sites
GEOSoft 67 Posted October 11, 2011 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 GeorgeQuestion 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
dirty 0 Posted October 11, 2011 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
shaqan 7 Posted October 11, 2011 (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 October 11, 2011 by shaqan Share this post Link to post Share on other sites