Jump to content

What's the problem there?


Frit
 Share

Recommended Posts

$GUI = GUICreate("Title", 150 , 40)
$CheckBox1 = GUICtrlCreateCheckBox('Start', 10, 10)
$window = "Client"
GUISetState ()


; When check box is marked, call function "Go"
While 1
    $msg = GUIGetMsg()
    If $msg = - 3 Then Exit
    If $msg = $CheckBox1 And GUICtrlRead($CheckBox1) = 1 Then
    WinActivate($window)
    Call ("Go")
    Endif
Wend

; Send Ctrl + left and Ctrl + right 9999 times with a pause between them.
Func Go()
For $x = 1 to 9999
Send("^+{LEFT}")
Sleep(1000)
Send("^+{RIGHT}")
Sleep(1000)
Next
EndFunc

I really don't know whats the problem (maybe with the For inside Function...)

Help me, please.

Edited by Frit
Link to comment
Share on other sites

  • Developers

I really don't know whats the problem (maybe with the For inside Function...)

Help me, please.

There is no problem with your script... when you Check the checkbox the func go will be run and loop 9999 times...

Unless that's not what you want ....

by the why... its standard practice to do Go() in stead of Call("go")

Edited by JdeB

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

Thats becasue.. its is looping 99999 times, with no cheecking to see if the Exit button was pressed.

You should set a HotKey like ESC or someting at the beginning of your script to close it...

HotKeySet("{ESC}", "ExitPrg")
$GUI = GUICreate("Title", 150 , 40)
$CheckBox1 = GUICtrlCreateCheckBox('Start', 10, 10)
$window = "Client"
GUISetState ()


; When check box is marked, call function "Go"
While 1
    $msg = GUIGetMsg()
    If $msg = - 3 Then Exit
    If $msg = $CheckBox1 And GUICtrlRead($CheckBox1) = 1 Then
    WinActivate($window)
    Call ("Go")
    Endif
Wend

; Send Ctrl + left and Ctrl + right 9999 times with a pause between them.
Func Go()
For $x = 1 to 9999
Send("^+{LEFT}")
Sleep(1000)
Send("^+{RIGHT}")
Sleep(1000)
Next
EndFunc

Func ExitPrg()
    Exit
EndFunc

this way, u can exit.. while inside that for loop

Edited by CHRIS95219
Link to comment
Share on other sites

I mean, if the function "go" is running, and i do something (in this case, unmark the checkbox) it stops.

Instead of a For loop, just use a While loop:

While GUICtrlRead($CheckBox1) == 1
   ;Do loop stuff
WEnd

[u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia

Link to comment
Share on other sites

same idea

; Press Esc to terminate script, Pause/Break to "pause"

#include <GuiConstants.au3>

Global $Paused, $Go
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "ExitPrg")
HotKeySet("{F9}", "Go")


$GUI = GUICreate("Title", 150, 40)
$CheckBox1 = GUICtrlCreateCheckbox('Start', 10, 10)
$window = "Client"
GUISetState()


; When check box is marked, call function "Go"
While 1
    $msg = GUIGetMsg()
    If $msg = -3 Then Exit
    
    $ans = GUICtrlRead($CheckBox1)
    If $ans = 1 Then
        WinActivate($window)
        $Go = 1
    Else
    ;WinActivate($window); other window ???
        $Go = 0
    EndIf
    
    If $Go Then Go()
    
WEnd

; =================== Functions =============


Func TogglePause()
    $Paused = Not $Paused
    While $Paused
        Sleep(100)
        ToolTip('Script is "Paused"', 0, 0)
    WEnd
    ToolTip("")
EndFunc  ;==>TogglePause

; Send Ctrl + left and Ctrl + right 9999 times with a pause between them.

Func Go()
    Send("^+{LEFT}")
    Sleep(1000)
    Send("^+{RIGHT}")
    Sleep(1000)
EndFunc  ;==>Go


Func ExitPrg()
    Exit
EndFunc  ;==>ExitPrg

8)

NEWHeader1.png

Link to comment
Share on other sites

  • Moderators

Instead of a For loop, just use a While loop:

While GUICtrlRead($CheckBox1) == 1
 ;Do loop stuff
WEnd
That's a good point neogia:
HotKeySet("{ESC}", "ExitPrg")
Global $window = "Client", $cCount = ''

$GUI = GUICreate("Title", 150 , 40)
$CheckBox1 = GUICtrlCreateCheckBox('Start', 10, 10)
GUISetState ()


; When check box is marked, call function "Go"
While 1
    $msg = GUIGetMsg()
    If $msg = - 3 Then Exit
    If $msg = $CheckBox1 And GUICtrlRead($CheckBox1) = 1 Then
        While GUICtrlRead($CheckBox1) = 1 And $cCount <= 9999
            $CKMsg = GUIGetMsg(); The 2 sleep 1000's really make this a moot point, the check box or hotkey is still the best way to exit if you need the sleeps()
            If $CKMsg = - 3 Then Exit; See above
            If Not WinActive($window) Then WinActivate($window)
            Send("^+{LEFT}")
            Sleep(1000)
            Send("^+{RIGHT}")
            Sleep(1000)
            $cCount = $cCount + 1
        WEnd
    Endif
Wend

Func ExitPrg()
    Exit
EndFunc
Might also want to look at maybe OnEventMode options rather than GUIGetMsg() if this is going to be your entire script. Edited by SmOke_N

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

with mine you can do other things while it is doing the loop

8)

Talking about exiting the function Val... do you BitAnd() the GUIGetMsg() too :)

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

Talking about exiting the function Val... do you BitAnd() the GUIGetMsg() too :)

i did find it in help

For Checkbox, Radio control several states can be returned as $GUI_FOCUS and $GUI_CHECKED,. So use BitAnd(GUICtrlRead($Item),$GUI_CHECKED) to test if the control is checked.

most times i just try to fix the problem at hand

.... if they SHOW ME SOME SCRIPT

8)

NEWHeader1.png

Link to comment
Share on other sites

  • Moderators

i did find it in help

most times i just try to fix the problem at hand

.... if they SHOW ME SOME SCRIPT

8)

LOL... well, I'll say this.. I will lay even odds that even BitAnd() is going to have to wait the 2 seconds before those 2 commands are done to work :)

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