Jump to content

Using two continuous loop in a script


Recommended Posts

Hello am a newbie to autoit,

I have a script that is meant to run continuously, now i want the script to send the file to my email, I have implemented INetSmtpMailCom but the problem is when i want to use a timer to tell it when to send the file, i have use another while infinite loop and if i put it in the first while infinite loop it wont send because the first while loop is still using the file.

If i put it outside the first while infinite loop, its stop the first loop and only the second loop runs.I"ve tried putting the timer loop in another script and including it into the first but i still encounter the same problem

Pleas any ideas on how to implement two infinite loops in a script.

thanks

Link to comment
Share on other sites

Infinite by definition means never ending, you can't have two endless loops, you should post your code and we can see what you need to get it working.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Func _TimerDiff()
   _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)
  AdlibEnable(_TimerDiff(), 300000 )  ; call this function again in 1 minute ; call this function again in 1 second
EndFunc

_TimerDiff()

I decided to use adlib i want it to send every 5minutes but it doesnt work instead it sends every second

please help

Link to comment
Share on other sites

You should use AdLibEnable at the beginning of your script - not in the function that is called by AdLibEnable.

You shouldn't name your functions like functions used by AutoIt or its UDFs. Your name (_TimerDiff) is only a "_" away from _Timer_Diff. That might get confusing.

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

AdlibEnable(_Timer(), 10000)  ; call this function again in 1 minute ; call this function again in 1 second
Func Timer()
   Local $iMinutes = 1
   Local $hTimer = TimerInit()
     If TimerDiff($hTimer) > ($iMinutes * 60000) Then _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)
  AdlibEnable(_Timer(), 10000)  ; call this function again in 1 minute ; call this function again in 1 second
EndFunc

_TimerDiff()

like this?

Link to comment
Share on other sites

sorry that was a mistake

AdlibEnable(Timer(), 10000)  ; call this function again in 1 minute ; call this function again in 1 second
Func Timer()
   Local $iMinutes = 1
   Local $hTimer = TimerInit()
     If TimerDiff($hTimer) > ($iMinutes * 60000) Then _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)
 
EndFunc

Timer()

If i do this, i get this error:

AdlibEnable(Timer(), 10000)

^ ERROR

Link to comment
Share on other sites

Try this:

AdlibRegister("Timer", 60 * 1000) ; Call this function every 60 seconds
; AdlibEnable("Timer", 60 * 1000) ; Call this function every 60 seconds - AutoIt version < 3.3.2.0

; Here goes the main part of your script which will be interrupted every 60 seconds to call function "Timer".

Func Timer()
    _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)
EndFunc   ;==>Timer

BTW: You seem to run an old version of Autoit. AdLibEnable has been replaced with AdLibRegister/AdLibUnregister in version 3.3.2.0.

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

#include <misc.au3>

AdlibRegister(Timer(), 60 * 1000) ; Call this function every 60 seconds

Func Timer()
    _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)

EndFunc   ;==>Timer

Hi, thanks for your suggestion, i created a new script and put this into it, but it runs once and exits, same thing happens when i put it in the main script

Link to comment
Share on other sites

There has to be some code that keeps the script "busy". My example just starts and ends. You have to put in some code.

This example runs forever and should call the function every 6 seconds to write the time to the console:

#include <misc.au3>
AdlibRegister("Timer", 6 * 1000) ; Call this function every 60 seconds
While 1
WEnd

Func Timer()
    ConsoleWrite(@Min & ":" & @SEC & @CRLF)
EndFunc   ;==>Timer

Important:

You have to use

AdlibRegister("Timer", 6 * 1000)
not
AdlibRegister(Timer(), 6 * 1000)
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

AdlibRegister("Timer", 60 * 1000) ; Call this function every 60 seconds

Func Timer()
    _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)

EndFunc   ;==>Timer

Did that and it didn't send at all

Link to comment
Share on other sites

The While loop was just an example! Replace the While loop I posted with your main code.

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

AdlibRegister("Timer", 60 * 1000) ; Call this function every 60 seconds

Func Timer()
    _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)

EndFunc   ;==>Timer

Did that and it didn't send at all

Do you get an return code or is @error set by _INetSmtpMailCOM?

Try to insert a

ConsoleWrite("***" & @CRLF)
at the begin of the function.

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

nolongthin here's a simple demonstration of how to handle nested loops. Hopefully it will give you an insight as to what is happening in your more complicated example. The best solution is still probably the one suggested by water.

MsgBox(0, "Msg from startup", "About to enter the first loop")

While 1 ; Loop 1
    MsgBox(0, "Msg from 1st Loop", "About to enter the second loop")

    While 1 ; Loop 2
        $ret = MsgBox(2, "Msg from 2nd Loop", "What do you want to do?")
        If $ret = 3 Then ; Abort
            ExitLoop 2 ; Get out of both loops
        ElseIf $ret = 4 Then ; Retry
            ExitLoop ; Only quit the second loop
        EndIf
    WEnd

WEnd

MsgBox(0, "Final Msg", "Aborted by user")

Notice what happens when you click Ignore!

Edited by czardas
Link to comment
Share on other sites

nolongthin,

I see. The resource (file) is in use by another process (probably your email client). You might try waiting longer or making sure that all handles are closed.

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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