cfdgm Posted May 15, 2012 Posted May 15, 2012 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.
Moderators Melba23 Posted May 15, 2012 Moderators Posted May 15, 2012 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
cfdgm Posted May 15, 2012 Author Posted May 15, 2012 thank you sir, i know it was something stupid on my part
Reg2Post Posted May 15, 2012 Posted May 15, 2012 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.
Spiff59 Posted May 15, 2012 Posted May 15, 2012 (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 May 15, 2012 by Spiff59
ripdad Posted May 16, 2012 Posted May 16, 2012 (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 May 16, 2012 by ripdad "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward
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