Jump to content

IF Then Else, Problem Please Help A Noob


Recommended Posts

Hey guys,

Need some help with code below. All i want is to ping google.com and if there are 0-3 "no replies" then it shoots up a msgbox stating hey it aint working. On the other hand if there are 4 replies i want a msg box stating all is well so play online. I am missing something but I don't know what exactly.

Any help is appreciated.

Thanks,

Atnextc

Dim $g=0
Run ("cmd.exe")
WinWaitActive ("Administrator: C:\Windows\system32\cmd.exe")
Send ("ping google.com")
Send ("{Enter}")

for $g=0 to 1
If @error = 0 Then
Msgbox (0, "Bien", "It's working so play online.")
elseif @error = 1 Then
Msgbox (0, "No Bien", "It's not working so call me.")
EndIf
next
        Send ("exit")
        Send ("{Enter}")
Edited by atnextc
Link to comment
Share on other sites

I think this can help you:

$iOk = 0
$n = 0

Do
    If Not Ping("www.google.com") = 0 Then ;try to do a ping
        $iOk = $iOk + 1 ;if it is ok then add one 
    Else
        $iOk = $iOk - 1 ;if it is not ok then subtract one
    EndIf
    $n = $n + 1 
Until $n = 4 ;do until 4 tries

If $iOk >= 3 Then ;If 3 or more of 4 times are ok then
    Msgbox (0, "Bien", "It's working so play online.")
Else
    Msgbox (0, "No Bien", "It's not working so call me.")
EndIf

You don't need to use cmd.exe to do a ping, AutoIt can do it by itself.

Link to comment
Share on other sites

That script is still not quite the proper way to do it, you should use a "For ... Next" loop to do that kind of work. Also "Not Ping() = 0" is the same as "Ping <> 0" which is the default anyway, so the same as "Ping()".

$iOk = 0
For $n = 1 To 4
    If Ping("www.google.com") Then ;try to do a ping
        $iOk = $iOk + 1 ;if it is ok then add one
    Else
        $iOk = $iOk - 1 ;if it is not ok then subtract one
    EndIf
Next

If $iOk >= 3 Then ;If 3 or more of 4 times are ok then
    Msgbox (0, "Bien - " & $iOk & " / 4", "It's working so play online.")
Else
    Msgbox (0, "No Bien - " & $iOk & " / 4", "It's not working so call me.")
EndIf
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...