Sign in to follow this  
Followers 0
Monolith

Help with looping function

4 posts in this topic

#1 ·  Posted (edited)

Hello

I'm quite relatively new to Autoit.

I am wanting to loop a "section" of a function every 30sec. I have tried [Do Until, continueloop] not sure what else i can use. Do i need to work with [While] ?

#include <IE.au3>
#include <file.au3>
#include <Date.au3>


_check()

Func _check() ; [u]I would like to loop this function indefinitely or until script is terminated, but once is finds the string in the page only goto: _sendmail() function after 5 emails sent[/u]
    $site1 = _IECreate("http://en.wikipedia.org/wiki/Leonardo_da_Vinci", 0, 0)
    _IELoadWait($site1)
    $txt = "this is an example"

    Sleep(500)
    $checking = _IEBodyReadHTML($site1)
        If Not StringInStr($checking, $txt) Then
        InetGet("http://en.wikipedia.org/wiki/Leonardo_da_Vinci", $file, 1, 0)
        Sleep(3000)
        Opt("WinTitleMatchMode", 3)
        ProcessClose("iexplore.exe")
        _sendmail()
    EndIf
EndFunc   ;==>_check


Func _sendmail()
    RunWait("blat.exe -server """ & $SMTPADD & """ -s """ & $SUBJECT & """ -attach """ & $file & """ -body """ & $body & """ -u """ & $USERNAME & """ -pw """ & $PASSWORD & """ -t """ & $TO & """ -f """ & $from & """ -log """ & $log & """", "", @SW_HIDE)
    ;RunWait('blat.exe' & ' ' & '-server' & ' ' & $SMTPADD & ' ' & ' -s'  & ' ' & $SUBJECT & ' ' & '-body' & ' ' & $BODY & ' ' & '-u' & ' ' & $USERNAME & ' ' & '-pw' & ' ' & $PASSWORD & ' ' & '-f' & ' ' & $from & ' ' & '-log' & ' ' & $log, @SW_HIDE)

sleep(120000)
_check()
EndFunc   ;==>_sendmail

thanks in advance

Edited by Monolith

Share this post


Link to post
Share on other sites



Hi again

I have now created like this

_check()

Func _check()
    $site1 = _IECreate("http://en.wikipedia.org/wiki/Leonardo_da_Vinci", 0, 0)
    _IELoadWait($site1)
    $txt = "Example txt HERE"
    Sleep(500)
    $checking = _IEBodyReadHTML($site1)

    If StringInStr($checking, $txt) Then
        _sleep()

    ElseIf Not StringInStr($checking, $txt) Then
        InetGet("http://en.wikipedia.org/wiki/Leonardo_da_Vinci", $file, 1)
        Sleep(3000)
        Opt("WinTitleMatchMode", 3)
        ProcessClose("iexplore.exe")
        _sendmail()
    EndIf
EndFunc   ;==>_check


Func _sleep()
    Sleep(60000)
    _Check()
EndFunc   ;==>_sleep



Func _sendmail()
    RunWait("blat.exe -server """ & $SMTPADD & """ -s """ & $SUBJECT & """ -attach """ & $file & """ -body """ & $body & """ -u """ & $USERNAME & """ -pw """ & $PASSWORD & """ -t """ & $TO & """ -f """ & $from & """ -log """ & $log & """", "", @SW_HIDE)
    ;RunWait('blat.exe' & ' ' & '-server' & ' ' & $SMTPADD & ' ' & ' -s'  & ' ' & $SUBJECT & ' ' & '-body' & ' ' & $BODY & ' ' & '-u' & ' ' & $USERNAME & ' ' & '-pw' & ' ' & $PASSWORD & ' ' & '-f' & ' ' & $from & ' ' & '-log' & ' ' & $log, @SW_HIDE)
    Sleep(120000)
    _check()
EndFunc   ;==>_sendmail

It is quite simple and i think is sufficient? :)

Share this post


Link to post
Share on other sites

Hello

I'm quite relatively new to Autoit.

I am wanting to loop a "section" of a function every 30sec. I have tried [Do Until, continueloop] not sure what else i can use. Do i need to work with [While] ?

#include <IE.au3>
#include <file.au3>
#include <Date.au3>


_check()

Func _check() ; [u]I would like to loop this function indefinitely or until script is terminated, but once is finds the string in the page only goto: _sendmail() function after 5 emails sent[/u]
    $site1 = _IECreate("http://en.wikipedia.org/wiki/Leonardo_da_Vinci", 0, 0)
    _IELoadWait($site1)
    $txt = "this is an example"

    Sleep(500)
    $checking = _IEBodyReadHTML($site1)
 If Not StringInStr($checking, $txt) Then
        InetGet("http://en.wikipedia.org/wiki/Leonardo_da_Vinci", $file, 1, 0)
        Sleep(3000)
        Opt("WinTitleMatchMode", 3)
        ProcessClose("iexplore.exe")
        _sendmail()
    EndIf
EndFunc ;==>_check


Func _sendmail()
    RunWait("blat.exe -server """ & $SMTPADD & """ -s """ & $SUBJECT & """ -attach """ & $file & """ -body """ & $body & """ -u """ & $USERNAME & """ -pw """ & $PASSWORD & """ -t """ & $TO & """ -f """ & $from & """ -log """ & $log & """", "", @SW_HIDE)
    ;RunWait('blat.exe' & ' ' & '-server' & ' ' & $SMTPADD & ' ' & ' -s' & ' ' & $SUBJECT & ' ' & '-body' & ' ' & $BODY & ' ' & '-u' & ' ' & $USERNAME & ' ' & '-pw' & ' ' & $PASSWORD & ' ' & '-f' & ' ' & $from & ' ' & '-log' & ' ' & $log, @SW_HIDE)

sleep(120000)
_check()
EndFunc ;==>_sendmail

thanks in advance

Welcome to the AutoIt forums Monolith :)

Probably the easiest way is to use AdlibEnable (or AdlibRegister in the Beta version). You can always stop the function being called by disabling with AdlibDisable. You won't need to have a sleep delay in your function in that case.

AdlibEnable("_check",3000);the function will be called every 3s
AdlibDisable() ;no function is called anymore

With the Beta version and AdlibRegister you can have more than one function which is called every time period with a different time period for each function.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Welcome to the AutoIt forums Monolith :)

Probably the easiest way is to use AdlibEnable (or AdlibRegister in the Beta version). You can always stop the function being called by disabling with AdlibDisable. You won't need to have a sleep delay in your function in that case.

AdlibEnable("_check",3000);the function will be called every 3s
AdlibDisable() ;no function is called anymore

With the Beta version and AdlibRegister you can have more than one function which is called every time period with a different time period for each function.

Thanks Martin for that intel, i'll test it out

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
Sign in to follow this  
Followers 0