Jump to content

Could I make this code "neater"?


Recommended Posts

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

Link to comment
Share on other sites

  • Moderators

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • Moderators

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.

Link to comment
Share on other sites

  • Moderators

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.

Link to comment
Share on other sites

  • Moderators

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.

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