Jump to content

Recommended Posts

I have heard that there is another way to go about using buttons to call functions rather than using Case-Select, perhaps a method that is more responsive to a user-click upon a button? I guess my question is, what am I doing wrong in my script below that is preventing the While loop from ending in the function the second I click on the "Stop" button?

#include <IE.au3>
#include <GuiConstants.au3>

;Draw the window
GuiCreate("Test", 214, 520)

;Draw Buttons
$go = GuiCtrlCreateButton("Go!", 61, 255, 100, 30)
GUICtrlSetColor(-1,0xFFFFFF)

$stop = GuiCtrlCreateButton("Stop", 61, 298, 100, 30)
GUICtrlSetColor(-1,0xFFFFFF)

;Button Actions
GUISetState()

While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE

Exit

Case $msg = $go

Go()

Case $msg = $stop

ExitLoop

EndSelect
WEnd



Func Go()

While 1

;;;;;Determine if button has been pressed
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
If $msg = $stop Then ExitLoop

Sleep(50)

$oIE = _IECreate()
_IENavigate($oIE, "http://www.autoitscript.com/forum/index.php?act=Search&f=")
_IELoadWait($oIE)
$oFrom = _IEFormGetObjByName($oIE, "sForm")
$oRelevant = _IEFormElementGetObjByName($oFrom, "sortby", 0)
$oRecent = _IEFormElementGetObjByName($oFrom, "sortby", 1)

For $i = 1 to 5
$oRelevant.checked = True
Sleep(1000)
$oRecent.checked = True
Sleep(1000)
Next

WEnd
EndFunc
Link to post
Share on other sites

you may want to try this with guievents for example:

CODE

#include <IE.au3>

#include <GuiConstants.au3>

opt("GUIOnEventMode", 1)

Global $Browse

;Draw the window

GUICreate("Test", 214, 520)

GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

;Draw Buttons

$go = GUICtrlCreateButton("Go!", 61, 255, 100, 30)

GUICtrlSetColor(-1, 0xFFFFFF)

GUICtrlSetOnEvent($go, "_Toggle")

$stop = GUICtrlCreateButton("Stop", 61, 298, 100, 30)

GUICtrlSetColor(-1, 0xFFFFFF)

GUICtrlSetOnEvent($stop, "_Toggle")

;Button Actions

GUISetState()

While 1

Sleep(50)

If $Browse Then

$oIE = _IECreate ()

_IENavigate ($oIE, "http://www.autoitscript.com/forum/index.php?act=Search&f=")

_IELoadWait ($oIE)

$oFrom = _IEFormGetObjByName ($oIE, "sForm")

$oRelevant = _IEFormElementGetObjByName ($oFrom, "sortby", 0)

$oRecent = _IEFormElementGetObjByName ($oFrom, "sortby", 1)

For $i = 1 To 5

$oRelevant.checked = True

Sleep(1000)

$oRecent.checked = True

Sleep(1000)

Next

EndIf

WEnd

Func _Toggle()

$Browse = Not $Browse

EndFunc ;==>_Toggle

Func _Exit()

Exit

EndFunc ;==>_Exit

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to post
Share on other sites

Thanks for your help, that seems a bit better but as soon as I make the script a bit more complicated and have it navigate to different pages, I run into the problem with the program not stopping and then it only stops after I press the button a hundred times. I'm fairly sure its the _IELoadWait() call that keeps it in a long sleep state. I edited the script with more calls involving _IELoadWait()

#include <IE.au3>
#include <GuiConstants.au3>

opt("GUIOnEventMode", 1)

Global $Browse
;Draw the window
GUICreate("Test", 214, 520)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

;Draw Buttons
$go = GUICtrlCreateButton("Go!", 61, 255, 100, 30)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetOnEvent($go, "_Toggle")

$stop = GUICtrlCreateButton("Stop", 61, 298, 100, 30)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetOnEvent($stop, "_Toggle")

;Button Actions
GUISetState()

While 1
Sleep(50)
If $Browse Then

$oIE = _IECreate ()
_IENavigate ($oIE, "http://www.autoitscript.com/forum/index.php?act=Search&f=")
_IELoadWait ($oIE)

_IENavigate ($oIE, "http://www.yahoo.com")
_IELoadWait ($oIE)

_IENavigate ($oIE, "http://www.google.com")
_IELoadWait ($oIE)

_IENavigate ($oIE, "http://www.yahoo.com")
_IELoadWait ($oIE)

_IENavigate ($oIE, "http://www.google.com")
_IELoadWait ($oIE)

_IENavigate ($oIE, "http://www.yahoo.com")
_IELoadWait ($oIE)

_IENavigate ($oIE, "http://www.google.com")
_IELoadWait ($oIE)

_IENavigate ($oIE, "http://www.yahoo.com")
_IELoadWait ($oIE)

_IENavigate ($oIE, "http://www.google.com")
_IELoadWait ($oIE)

_IENavigate ($oIE, "http://www.autoitscript.com/forum/index.php?act=Search&f=")
_IELoadWait ($oIE)
$oFrom = _IEFormGetObjByName ($oIE, "sForm")
$oRelevant = _IEFormElementGetObjByName ($oFrom, "sortby", 0)
$oRecent = _IEFormElementGetObjByName ($oFrom, "sortby", 1)

For $i = 1 To 5
$oRelevant.checked = True
Sleep(1000)
$oRecent.checked = True
Sleep(1000)
Next
EndIf
WEnd

Func _Toggle()
$Browse = Not $Browse
EndFunc;==>_Toggle

Func _Exit()
Exit
EndFunc;==>_Exit

I'm thinking that I might just have to have two seperate programs which is stupid, but I don't think I have any other choice. I just dont understand why the 'Esc' key exits the program instantly.

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...