Sign in to follow this  
Followers 0
cfdgm

Kill process hourly

6 posts in this topic

Hello all, I am a hobbyist programmer and new to the auto it scene, I currently am studying C++ and C# and wish to further expand my abilities with autoit, but I am struggling with learning this language.

#include <Date.au3> ;
Dim $proc1 = "manager.exe"
$HourCounter = 00
While 1
If @Hour = 00 Then
$HourCounter = 00
EndIf
If @Hour <> $HourCounter Then
If ProcessExists($proc1) Then
ProcessClose($proc1)
endif
If @Hour - $HourCounter <> 0 Then
$HourCounter = @HOUR
EndIf
Sleep(5000)
WEnd

I am receiving this error.

(17) : ==> "Wend" statement with no matching "While" statement.:

WEnd

I have concluded that I am simply making some rookie mistake here.

The goal of this project is to kill another process (manager.exe) at an hourly rate. Feel free to critique the efficiency of this script, while I am still learning I will appreciate pointers that will lead to stronger programming skills.

Thank you for your time.

Share this post


Link to post
Share on other sites



cfdgm,

Welcome to the AutoIt forum. ;)

You were not closing the outer If...EndIf structure:

#include <Date.au3> ;
Global $proc1 = "manager.exe"
$HourCounter = 00
While 1
    If @HOUR = 00 Then
        $HourCounter = 00
    EndIf
    If @HOUR <> $HourCounter Then
        If ProcessExists($proc1) Then
            ProcessClose($proc1)
        EndIf
        If @HOUR - $HourCounter <> 0 Then
            $HourCounter = @HOUR
        EndIf
        Sleep(5000)
    EndIf ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
WEnd

Other tips:

- Indent the code - it makes it easier to spot mistakes like that. :)

- Do not use Dim[/]i - the Variables - using Global, Local and ByRef tutorial in the Wiki explains why. :)

You might want to install the full SciTE4AutoIt3 package that you will find here - it has a whole bunch of extra utilities to help you ciode in AutoIt, and particularly one called Tidy which does the indenting for you. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

thank you sir, i know it was something stupid on my part

Share this post


Link to post
Share on other sites

Feel free to critique the efficiency of this script, while I am still learning I will appreciate pointers that will lead to stronger programming skills.

I will start of with this:

Your code will kill the process (if it is running) every 5 seconds or so (depending on how fast the host machine is) and not at an hourly interval.

Also, I think there is a few if statements you could remove.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Since you invited us to comment on efficiency...

You have the following 2 tests, one nested within the other...

If @HOUR <> $HourCounter Then...
        If @HOUR - $HourCounter <> 0 Then...

If the first test is true , then we know the second will also always be true.

I would think you could get by with just this...

#include <Date.au3>
Global $proc1 = "manager.exe"

$HourCounter = @HOUR ; wait an hour before first process kill
;$HourCounter = @HOUR - 1 ; force first process kill immediately upon script execution
While 1
    If $HourCounter <> @HOUR Then
        If ProcessExists($proc1) Then ProcessClose($proc1)
        $HourCounter = @HOUR
    EndIf
    Sleep(5000)
WEnd

typo

Edited by Spiff59

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Or, instead of polling for the hour, one could do something like this...

Local $iMilliseconds = _MillisecondsToNextHour()
AdlibRegister('_MyFunction', $iMilliseconds)

MsgBox(0, '_MillisecondsToNextHour()' , $iMilliseconds);<-- just for show

While 1

    ; Loop Code goes here, if needed

    Sleep(10)
WEnd

Func _MillisecondsToNextHour()
    Local $time = 3600000
    $time -= @MIN * 60000
    $time -= @SEC * 1000
    Return $time
EndFunc

Func _MyFunction()
    MsgBox(0, '', 'Time is: ' & @HOUR & ':' & @MIN & ':' & @SEC);<-- just for show

    ; Function Code goes here
    ; If ... Then ...

    AdlibRegister('_MyFunction', _MillisecondsToNextHour())
EndFunc
Edited by ripdad

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

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