dimitrib Posted March 13, 2012 Share Posted March 13, 2012 I have this script and I cannot figure out why on earth it is giving me an error message. each time I run the scrip it gives me an error code referencing the Sleep 5000 . what is wrong with the code? #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <IE.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 347, 113, 192, 124) $Button1 = GUICtrlCreateButton("START Refresh Browser", 24, 72, 131, 25) $Label1 = GUICtrlCreateLabel("Click START to refresh browser every 5 seconds", 32, 16, 234, 17) $Button2 = GUICtrlCreateButton("Stop Refresh Browser", 176, 72, 115, 25) $Label2 = GUICtrlCreateLabel("Click Stop to close window and stop refreshing the browser", 32, 40, 282, 17) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 Do $oIE = _IECreate ("somewebpage.com/home.aspx") Sleep 5000 ContinueLoop Send("!F5") ;F5 key pressed to refresh browser Sleep 5000 ;After 5 seconds it refreshes browser again Until case $Button2 ExitLoop Sleep 5000 Exit EndSwitch WEnd Link to comment Share on other sites More sharing options...
Developers Jos Posted March 13, 2012 Developers Share Posted March 13, 2012 Did you check the helpfile for the correct syntax? Also install the full version of SciTE4AutoIt3, open the script in SciTE and hit F5 which will first run au3check and tells you about all syntax errors. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
dimitrib Posted March 13, 2012 Author Share Posted March 13, 2012 I've fixed the sleep (5000) line of the code. Now I've updated the script and it auto-refreshes, but the problem is that it opens a new IE window every 5s and the stop refresh doesn't work. Link to comment Share on other sites More sharing options...
dimitrib Posted March 13, 2012 Author Share Posted March 13, 2012 (edited) that part I found out on my own, but now the script auto refreshes itself into a new IE browser window and the stop refresh button doesn't work #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <IE.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Quick_Change_Auto_Refreshv0.1", 347, 113, 192, 124) $Button1 = GUICtrlCreateButton("START Refresh Browser", 24, 72, 131, 25) $Label1 = GUICtrlCreateLabel("Click START to refresh browser every 5 seconds", 32, 16, 234, 17) $Button2 = GUICtrlCreateButton("Stop Refresh Browser", 176, 72, 115, 25) $Label2 = GUICtrlCreateLabel("Click Stop to close window and stop refreshing the browser", 32, 40, 282, 17) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 Do $oIE = _IECreate ("somepage.com/home.aspx") Sleep(5000) ;timer 5 seconds it refreshes browser again ContinueLoop Send("!F5") ;F5 key pressed to refresh browser Sleep(5000) ;timer 5 seconds it refreshes browser again Until $nMsg = "Exit" case $Button2 ExitLoop Exit EndSwitch WEnd Edited March 13, 2012 by dimitrib Link to comment Share on other sites More sharing options...
BrewManNH Posted March 13, 2012 Share Posted March 13, 2012 (edited) This line shouldn't be inside the Do loop -> $oIE = _IECreate ("somepage.com/home.aspx") Edited March 13, 2012 by Melba23 URL changed at OP's request If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
dimitrib Posted March 13, 2012 Author Share Posted March 13, 2012 how would I close up this case $Button2 at the bottom of the script? the erorr is no matching "select" or Switch" statement. expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <IE.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Auto Refresh IE Window", 347, 113, 192, 124) $Button1 = GUICtrlCreateButton("START Refresh Browser", 24, 72, 131, 25) $Label1 = GUICtrlCreateLabel("Click START to refresh browser every 5 seconds", 32, 16, 234, 17) $Button2 = GUICtrlCreateButton("Stop Refresh Browser", 176, 72, 115, 25) $Label2 = GUICtrlCreateLabel("Click Stop to close window and stop refreshing the browser", 32, 40, 282, 17) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### HotKeySet("!{x}", "_Exit") Opt("WinTitleMatchMode", 3) While 1 Sleep(30000) ; Tell the script to pause for 5 seconds $nMSG = GUIGetMsg() Switch $nMSG Case $GUI_EVENT_CLOSE Exit Case $Button1 Do $nMSG = GUIGetMsg() $title = WinGetTitle("website - Internet Explorer", "") If WinExists($title) Then ; WinActivate($title) ; WinWaitActive($title) ; Send("{F5}") ; Sleep (30000) Else Sleep (10) EndIf case $Button2 $msg = "End Auto Refresh" Func _Exit() ; EndFunc ; EndSwitch WEnd Link to comment Share on other sites More sharing options...
BrewManNH Posted March 13, 2012 Share Posted March 13, 2012 You need to close the Do loop in the Case statement above the $button2 case statement. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
dimitrib Posted March 16, 2012 Author Share Posted March 16, 2012 okay using the ctrl T option i was able to produce a beautiful script without errors. now there are two troubles with the project. 1) the buttons do not really work 2) the X button on top doesn't kill the script 3) it doesn't auto refresh at the specific intervals. expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <IE.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Auto Refresh IE Window", 347, 113, 192, 124) $Button1 = GUICtrlCreateButton("START Refresh Browser", 24, 72, 131, 25) $Label1 = GUICtrlCreateLabel("Click START to refresh browser every 5 seconds", 32, 16, 234, 17) $Button2 = GUICtrlCreateButton("Stop Refresh Browser", 176, 72, 115, 25) $Label2 = GUICtrlCreateLabel("Click Stop to close window and stop refreshing the browser", 32, 40, 282, 17) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### HotKeySet("!{x}", "_Exit") Opt("WinTitleMatchMode", 3) ; This is to tell the script to only refresh the EXACT window, incase there are similar windows. Such as: Window 1, Window 2. $oIE = _IECreate ("somepage.com/home.aspx") While 1 ; Main loop begins $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 Do Sleep (30000) ; Sleep for 5 seconds $title = WinGetTitle("SomeTitle - Microsoft Internet Explorer") If WinExists($title) Then WinActivate($title) WinWaitActive($title) ContinueLoop Send("!F5") ;F5 key pressed to refresh browser Sleep (30000) ;After 5 seconds it refreshes browser again case $Button2 Func _Exit() Sleep (30000) Exit EndFunc EndSwitch WEnd Link to comment Share on other sites More sharing options...
BrewManNH Posted March 16, 2012 Share Posted March 16, 2012 (edited) I've corrected the numerous errors in your original script, and also made a lot of changes so that it will actually do what it is you're trying to do. It doesn't rely on using Send to try and send a command to a window, which is very unreliable if someone is using the computer at the same time. Plus it will only refresh the window you created when the script is run, so that you are 100% sure you're only refreshing that window, and doesn't activate the window all the time which would drive a normal user insane because the script is constantly shifting focus to another window every 5 seconds. Look this script over and see what I have done with it, learn from this example and I think you'll be better off. expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <IE.au3> #region ### START Koda GUI section ### Form= $Form1 = GUICreate("Auto Refresh IE Window", 347, 113, 192, 124) $Button1 = GUICtrlCreateButton("START Refresh Browser", 24, 72, 131, 25) $Label1 = GUICtrlCreateLabel("Click START to refresh browser every 5 seconds", 32, 16, 234, 17) $Button2 = GUICtrlCreateButton("Stop Refresh Browser", 176, 72, 115, 25) $Label2 = GUICtrlCreateLabel("Click Stop to close window and stop refreshing the browser", 32, 40, 282, 17) GUISetState(@SW_SHOW) #endregion ### END Koda GUI section ### HotKeySet("!{x}", "_Exit") Opt("WinTitleMatchMode", 3) ; This is to tell the script to only refresh the EXACT window, incase there are similar windows. Such as: Window 1, Window 2. $oIE = _IECreate("somepage.com/home.aspx") _IEErrorHandlerRegister("MyErrFunc") While 1 ; Main loop begins $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Button1 = ' & $Button1 & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console AdlibRegister("_Refresh", 5000) ; run the function every 5 seconds Case $Button2 ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Button2 = ' & $Button2 & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console AdlibUnRegister("_Refresh") ; stop running the function EndSwitch WEnd Func _Exit() Exit EndFunc ;==>_Exit Func _Refresh() $title = ObjName($oIE, 1) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $title = ' & $title & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console If $title = "IWebBrowser2" Then _IEAction($oIE, "refresh") ; refreshes the page whether it has focus or not Else MsgBox(64, "Error", "The browser object doesn't exist, closing the script") ; the window was closed, close the script Exit EndIf ; Close the If/Then function EndFunc ;==>_Refresh Func MyErrFunc() MsgBox(64, "Error", "An error has occurred, closing this script") Exit EndFunc ;==>MyErrFunc EDIT: I wanted to mention that there are several ConsoleWrites in this demo to show you what's going on in the script as it's running. They are not needed to make the script run, just for demonstration purposes. Edited March 16, 2012 by BrewManNH If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
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