Jump to content

(If else) Do until - Not working


Recommended Posts

Hello, i am creating  a program that 

1. it will check if the computer is connected to the internet 
2. will display a message if it is connected 
3.if not connected then it will continue to check until the computer connects to the internet then it runs the function which would have been executed if the computer was connected to the internet.

what i tried.

i connected my computer to the internet and run the code. Which displayed the msgbox that am connected

i later turn my internet off and run the cold , i saw it running in process list.. i waited for 5 minutes and it was still waiting for internet connection (running), but when i turned the internet on and got internet connectivity, the app just close without displaying the msg that am connected.


Please need help where i went wrong. or if anything should be added.

 

this is the code

#AutoIt3Wrapper_icon=1.ico
$ping = Ping("www.google.com")
If Not @error Then
    MsgBox("", "AlexFing", "You are connect")
Else
    Do
        $ping = Ping("www.google.com")
    Until Not @error
EndIf

 

Link to comment
Share on other sites

Wouldn't this work as well?

#AutoIt3Wrapper_icon=1.ico
Do
    $ping = Ping("www.google.com")
Until Not @error
MsgBox("", "AlexFing", "You are connect")

 

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

:)

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

Another option using _WinAPI_IsInternetConnected() function:

#AutoIt3Wrapper_icon=1.ico
#include <WinAPIDiag.au3>
Local $bMsgBox = False
While 1
    If _WinAPI_IsInternetConnected() Then
        If $bMsgBox = False Then
            MsgBox("", "AlexFing", "You are connect")
            $bMsgBox = True
        EndIf
    Else
        $bMsgBox = False
    EndIf
    Sleep(1000) ;~ Sleep 1 Second
WEnd

 

Link to comment
Share on other sites

I assume - according to the OPs requirements in the OP - that the loop should be exited on successful ping.

Quote

3.if not connected then it will continue to check until the computer connects to the internet then it runs the function which would have been executed if the computer was connected to the internet.

So an ExitLoop should be added ;)

#AutoIt3Wrapper_icon=1.ico
#include <WinAPIDiag.au3>
While 1
    If _WinAPI_IsInternetConnected() Then
        MsgBox("", "AlexFing", "You are connect")
        ExitLoop
    EndIf
    Sleep(1000) ;~ Sleep 1 Second
WEnd

 

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

BTW: The wiki holds a code snippet that allows to check internet connectivity without having to run Ping (here external ping is blocked by the FW):

https://www.autoitscript.com/wiki/AutoIt_Snippets#IsInternetConnected

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

That's correct. I didn't check the WinAPIDiag UDF but now it seems the snippet in the wiki is obsolete.

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

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

×
×
  • Create New...