nolongthin Posted April 17, 2012 Posted April 17, 2012 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
BrewManNH Posted April 17, 2012 Posted April 17, 2012 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 GudeHow 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
nolongthin Posted April 17, 2012 Author Posted April 17, 2012 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
water Posted April 17, 2012 Posted April 17, 2012 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 2024-07-28 - Version 1.6.3.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 (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
nolongthin Posted April 17, 2012 Author Posted April 17, 2012 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?
nolongthin Posted April 17, 2012 Author Posted April 17, 2012 sorry that was a mistakeAdlibEnable(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
water Posted April 17, 2012 Posted April 17, 2012 (edited) 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 April 17, 2012 by water My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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
nolongthin Posted April 17, 2012 Author Posted April 17, 2012 #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
water Posted April 17, 2012 Posted April 17, 2012 (edited) 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)notAdlibRegister(Timer(), 6 * 1000) Edited April 17, 2012 by water My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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
nolongthin Posted April 17, 2012 Author Posted April 17, 2012 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
nolongthin Posted April 17, 2012 Author Posted April 17, 2012 there is a previous while 1 in the main code, if i put the second it interrupts the first, and if the first still work the second would not it would give error that the process is being used by another
water Posted April 17, 2012 Posted April 17, 2012 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 2024-07-28 - Version 1.6.3.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 (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
water Posted April 17, 2012 Posted April 17, 2012 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 2024-07-28 - Version 1.6.3.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 (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
czardas Posted April 17, 2012 Posted April 17, 2012 (edited) 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 April 17, 2012 by czardas operator64 ArrayWorkshop
nolongthin Posted April 17, 2012 Author Posted April 17, 2012 Hi still dint work gives this error Description:The process cannot access the file because it is being used by another process.
kylomas Posted April 17, 2012 Posted April 17, 2012 nolongthin, Do you REALLY want to email a file to yourself every minute that this script is running? Perhaps there is another solution to what you are trying to do. 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
nolongthin Posted April 17, 2012 Author Posted April 17, 2012 @kylomasActually i want to email the file to myself every 30min that the script is run but am just testing it with 1 minute
czardas Posted April 17, 2012 Posted April 17, 2012 (edited) kylomas is right, I think you need to tell us more about this. What exactly are you sending and why? Edited April 17, 2012 by czardas operator64 ArrayWorkshop
kylomas Posted April 17, 2012 Posted April 17, 2012 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now