Jump to content
AlexFing17

(If else) Do until - Not working

Recommended Posts

AlexFing17

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

 

Share this post


Link to post
Share on other sites
water

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 (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
water

:)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Subz

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

 

Share this post


Link to post
Share on other sites
water

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 (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
water

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 (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Subz

@water Wasn't 100% sure with regards Alex wanted it running continuous or not, so I assumed the opposite :)

It looks like the snippet is the same code as _WinAPI_IsInternetConnected or have I missed something?

Share this post


Link to post
Share on other sites
water

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 (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
AlexFing17

Thanks Guys. I made corrections with the help from both codes. and everything works as expected.

Thank you once again

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

  • Similar Content

    • Vikramjeet
      By Vikramjeet
      $oExcel = ObjCreate("Excel.Application") $oExcel.Visible = 0 #include <MsgBoxConstants.au3> WinActivate("MyApplication") ;Make my application active Local $hWnd = WinWaitActive("MyApplication", "", 5) ;Waits for my application to be the active application $oExcel.Application.WorkBooks.Open("C:\Users\Charlie\Desktop\Data.xlsx") ;Opens an excel file local $iCell = $oExcel.Application.Cells(31,1).Value ;Reads the number from row 1, cell 31 of the open excel file If $hWnd Then For $a = 1 to $iCell Send("G*S/") Send($oExcel.Application.Cells($a,1).Value) Send("'SET/US") Sleep(1000) Send("{ENTER}") Sleep(2000) Send("MB") Send("{ENTER}") Sleep(2000) $file = @ScriptDir & "\DATA.log" $iNum = StringRegExp(FileRead($file), "(?sm).*^\h*(\d{1,3})", 1)[0] ;I am reading the last instance of 1-3 numeric values in the DATA.log file ConsoleWrite($iNum & @CRLF) ;;;This is what I want to add - I also want to read the second last line of the DATA.log file and keep looking for an error 'Invalid Request' ;;;If I find the error 'Invalid Request' then I go back to the start - If $hWnd Then ;;;If I do not find the error then proceed to the below steps If $hWnd Then For $i = 1 To $iNum Send("GSET"& $i &"/USR") Sleep(500) Send("{ENTER}") Sleep(1000) Next Else MsgBox(0, "", '"MyApplication" window not found.') EndIf Next EndIf $oExcel.Application.Quit In the above script, I want to add a condition after 'ConsoleWrite($iNum & @CRLF)'. If I find the text 'Invalid Request' in the second last line of the active DATA.log file then I go back to the start of the loop. However if I do not find the text 'Invalid Request' in the second last line of the Data.log file then i proceed to the further steps
    • ShakeelAhmad
      By ShakeelAhmad
      I've to upload different number of photos online in different assignments. There is a problem that all photos cannot be selected at once to upload. I have to choose and upload photos one by one. For this purpose I have made a script to automate whatever I have to do manually for choosing and uploading photos one by one.
      Please see my script below and check the last "MouseClick" command. This command clicks the button to choose and upload next photo. The problem I'm facing is; the last "MouseClick" works 1 step extra when all photos have been selected and uploaded. I mean if 7 photos are to be uploaded, this command opens the box from where next photo is selected and uploaded then it again opens the box and next photo is choosen and so on.... when last photo is selected and uploaded, this button once again opens the box. When all photos are uploaded, it should not click the button to select next photo. Please suggest how can I resolve this issue.
      #include <AutoItConstants.au3> Sleep(200) HotKeySet("{ESC}","Quit") ;Press ESC key to quit Send("{ALT DOWN}") Send("{TAB}") Send("{ALT UP}") Sleep(200) Local $photos = InputBox("Question", "How many photos to upload?", "#", "", _ - 1, -1, 0, 0) ; How many photos to upload Local $selector = 0 While $photos <> $selector MouseClick("Left", 281, 238, 1) ; mouse click on very first photo in the box. if $selector = 0 Then Send("{ENTER}") ; for selecting very first photo from "open" window. Sleep(800) Else sleep(200) Send("{RIGHT " & $selector & "}") ; for selecting 2nd to onward photos from "open" window. sleep(1000) Send("{ENTER}") sleep(1000) EndIf MouseClick("Left", 495, 198, 1) ; for clicking a button to choose next photo to upload $selector = $selector + 1 WEnd Beep(1500, 300) ; beep when all photos uploaded Exit Regards,
       
      Shakeel
    • WoodGrain
      By WoodGrain
      Hi guys,
      I'm learning about GUI's, I'm trying the below code, the idea being if I press the letter "e" while I have the GUI open I want the label color to change to green (I'm using a UDF for label colors). But every time I press "e" on my keyboard I just get a "ding" sound from my speakers and nothing changes with the label.
      I've looked at using something like "While GUIGetMsg() <> $GUI_EVENT_CLOSE" as I've seen it in other code instead of "While 1", but I don't think it's relevant.
      #include <GUIConstantsEx.au3>; for GUI... #include <GUIRichLabel.au3>; UDF for rich text label fonts #include <Misc.au3>; for _IsPressed $myLetter = "e" $hGUI = GUICreate("test", 700, 60) $lbl2 = _GUICtrlRichLabel_Create($hGUI, '<font color="purple">' & $myLetter & '</font>', 10, 10); , 260, 25 GUISetState(@SW_SHOW) Local $hDLL = DllOpen("user32.dll") While 1 if _IsPressed(Hex($myLetter), $hDLL) Then While _IsPressed(Hex($myLetter), $hDLL) Sleep(250) WEnd _GUICtrlRichLabel_SetData($lbl2, '<font color="green">' & $myLetter & '</font>') Sleep(2000) DllClose($hDLL) Exit EndIf Sleep(50) WEnd DllClose($hDLL) I am using an array of letters that I'm wanting to do this for, but as I can't get it to work I've stripped it down to the simplest code I can think of to try and get this working first. Appreciate any help.
      Thanks!
    • AndreasNWWWWW
      By AndreasNWWWWW
      Hi, i'm curious if this is even possible, i want to do an action if the ini file contains current values under a section.
      for my test i'm looking for 100,200,300,400,500
      and if any of those excits i want to pop a msgbox with the number in the section.
      i can in my example find one, but it does not check everyone. why?  what am i missing?
      Local $iscore810[5] = [100,200,300,400,500] Local $iMax800 = 5 While 1 ;~     Send("{pause}") ;;func les ini fil     $var = IniReadSection("Area.ini", "modus")     If @error Then         MsgBox(4096, "Error", "Unable to read section.")     Else          For $number = 1 To $var[0][0] If $var[$number][1] == $iscore810[3] Then       MsgBox($MB_SYSTEMMODAL, "FAnt den på", $var[$number][0], 5) EndIf                       Next     EndIf     exit WEnd  
    • Aleksandar
      By Aleksandar
      So can anyone help me ? I need to restart program when condition is not met ...

×