Jump to content
Sign in to follow this  
Solomon

Could I make this code "neater"?

Recommended Posts

Solomon

I have some code that I need to have run every 5 seconds, to check to see if a file and process exist, and exit if they dont.

If ProcessExists("Backup.exe") Then
FileMove("G:\Backup\*.jaz", "C:\Backup HQ\*.jaz")
EndIf
If Not ProcessExists("Backup.exe") Then Exit
Sleep(5000)

Is it possible to use something other than a combination of Sleep(5000) and repeating the above code millions of times? I mean, its working, and working fine, so perhaps I should just live with it, but I was thinking that the code would look nicer if it did [something] until [something else].

Share this post


Link to post
Share on other sites
SmOke_N

AdlibEnable('_CheckForProcess', 5000); will check process every 5 seconds or so

While 1
    Sleep(1000)
WEnd

Func _CheckForProcess()
    If ProcessExists("Backup.exe") Then
        FileMove("G:\Backup\*.jaz", "C:\Backup HQ\*.jaz")
    Else
        Exit
    Exit
EndFunc


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
Valuater

maybe

; Press Esc to terminate script, Pause/Break to "pause"

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
HotKeySet("+!d", "ShowMessage") ;Shift-Alt-d

;;;; Body of program would go here;;;;
While 1
    Sleep(100)
WEnd
;;;;;;;;

Func TogglePause()
    $Paused = Not $Paused
    If $Paused Then AdlibEnable("myadlib", 5000)
    While $Paused
        Sleep(100)
        ToolTip('Script is "Running"', 0, 0)
    WEnd
    ToolTip("")
    AdlibDisable ( )
EndFunc  ;==>TogglePause

Func Terminate()
    Exit 0
EndFunc  ;==>Terminate

Func ShowMessage()
    MsgBox(4096, "", "This is a message.")
EndFunc  ;==>ShowMessage

Func myadlib()
    If ProcessExists("Backup.exe") Then
        FileMove("G:\Backup\*.jaz", "C:\Backup HQ\*.jaz")
    EndIf
EndFunc  ;==>myadlib

********** not tested

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
MHz

While ProcessExists('Backup.exe')
    FileMove("G:\Backup\*.jaz", "C:\Backup HQ\*.jaz")
    Sleep(5000)
WEnd

Share this post


Link to post
Share on other sites
Valuater

While ProcessExists('Backup.exe')
    FileMove("G:\Backup\*.jaz", "C:\Backup HQ\*.jaz")
    Sleep(5000)
WEnd

sometimes.... "Less is Better"

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
SmOke_N

sometimes.... "Less is Better"

8)

I keep trying to tell my wife that :):mellow::)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
Solomon

Blimey, that was quick! :)

Thanks very much, guys!

Share this post


Link to post
Share on other sites
SmOke_N

Blimey, that was quick! :)

Thanks very much, guys!

Yeah... some of these guys have nothing better to do other than sit around and help :) (or we have better things to do... but our priorities are screwed)... so you gotta check frequently :mellow:.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
MHz

I keep trying to tell my wife that :o:mellow::)

While you are using it in a loop, your wife will be happy. :)

Share this post


Link to post
Share on other sites
seandisanti

While you are using it in a loop, your wife will be happy. :)

unless every iteration is executing on the girlfriend.... speaking of... what an awesome weekend.

Share this post


Link to post
Share on other sites
SmOke_N

unless every iteration is executing on the girlfriend.... speaking of... what an awesome weekend.

Ha!!... I'll have to remember to ask about it... (The weekend that is) ... I don't have a girlfriend to tell her about... but I love hearing about hers!! :mellow::)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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  

×