Sign in to follow this  
Followers 0
bucky002

How do I make a script repeat?

26 posts in this topic

What's the code?

Thanks.

Share this post


Link to post
Share on other sites



choice 1

While 1

Wend

choice 2

For $i = x to x

next

hope that helps you...

Share this post


Link to post
Share on other sites

So like this?

While 1
Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("Heyheyheyheyheyheyheyheyhey.")
WinClose("Untitled - Notepad")
WinWaitActive("Notepad", "The text in the Untitled file has changed")
Send("!n")
Wend

Will it only repeat once?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

yeah, like that. and no, it will repeat forever...

if u want it to repeat once u would do:

For $i = 1 to 2
Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("Heyheyheyheyheyheyheyheyhey.")
WinClose("Untitled - Notepad")
WinWaitActive("Notepad", "The text in the Untitled file has changed")
Send("!n")
Next
Edited by CHRIS95219

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Or

$loop = 0
While $loop < 5
Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("Heyheyheyheyheyheyheyheyhey.")
WinClose("Untitled - Notepad")
WinWaitActive("Notepad", "The text in the Untitled file has changed")
Send("!n")
$loop = $loop + 1
Wend
Edited by =sinister=

Share this post


Link to post
Share on other sites

Or

$loop = 0
While $loop < 5
Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("Heyheyheyheyheyheyheyheyhey.")
WinClose("Untitled - Notepad")
WinWaitActive("Notepad", "The text in the Untitled file has changed")
Send("!n")
$loop = loop + 1
Wend
you forgot to put "$" before loop... $loop + 1. lol.

just thought i'd point that out, so bucky does'nt get confused...

$loop = 0
While $loop < 5
Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("Heyheyheyheyheyheyheyheyhey.")
WinClose("Untitled - Notepad")
WinWaitActive("Notepad", "The text in the Untitled file has changed")
Send("!n")
$loop = $loop + 1
Wend

Share this post


Link to post
Share on other sites

Lol, good I want it to reapeat forever thanks, but how do I stop it?

Share this post


Link to post
Share on other sites

...if u want it to repeat once u would do:

For $i = 1 to 2
For $i = 1 to 1
...or no for/next loop at all...

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

For $i = 1 to 1
...or no for/next loop at all...
but would'nt 1 to 1 loop it 0 times?

which would mean it would'nt loop at all?

Share this post


Link to post
Share on other sites

Lol, good I want it to reapeat forever thanks, but how do I stop it?

for the While/Wend loop you would do ExitLoop

Share this post


Link to post
Share on other sites

Like this?

Loop
Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("Heyheyheyheyheyheyheyheyhey.")
WinClose("Untitled - Notepad")
WinWaitActive("Notepad", "The text in the Untitled file has changed")
Send("!n")
Exit

Thanks.

Share this post


Link to post
Share on other sites

Like this?

Loop
Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("Heyheyheyheyheyheyheyheyhey.")
WinClose("Untitled - Notepad")
WinWaitActive("Notepad", "The text in the Untitled file has changed")
Send("!n")
Exit

Thanks.

nope...

while 1
Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("Heyheyheyheyheyheyheyheyhey.")
WinClose("Untitled - Notepad")
WinWaitActive("Notepad", "The text in the Untitled file has changed")
Send("!n")
ExitLoop
wend
;then whatever code you want here...

but the ExitLoop should be in a function like:

while 1
If _isPressed("01") then MouseClicked()
else
;;
endif
wend

Func MouseClicked()
MsgBox(0, "", "")
ExitLoop
EndFunc

np..

Share this post


Link to post
Share on other sites

Okay I'll see if I can do it.

Thank you.

Share this post


Link to post
Share on other sites

nope...

while 1
Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("Heyheyheyheyheyheyheyheyhey.")
WinClose("Untitled - Notepad")
WinWaitActive("Notepad", "The text in the Untitled file has changed")
Send("!n")
ExitLoop
wend
;then whatever code you want here...

but the ExitLoop should be in a function like:

while 1
If _isPressed("01") then MouseClicked()
else
;;
endif
wend

Func MouseClicked()
MsgBox(0, "", "")
ExitLoop
EndFunc

np..

Hmm...

This didn't work for me. It just stopped after the first time.

while 1
Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("Heyheyheyheyheyheyheyheyhey.")
WinClose("Untitled - Notepad")
WinWaitActive("Notepad", "The text in the Untitled file has changed")
Send("!n")
ExitLoop
wend
;then whatever code you want here...

Thanks again.

Share this post


Link to post
Share on other sites

Thanks for your help, but I have to get off.

Thanks again I think I figured it out.

Share this post


Link to post
Share on other sites

but would'nt 1 to 1 loop it 0 times?

which would mean it would'nt loop at all?

nope... just run the code that you wrote and see how many times it runs. :-)

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

yeah, u need to have the exit loop in a function... here is an example.. with a GUI and stuff.

#include <GuiConstants.au3>;Functions needed for most GUI Code
GuiCreate("Your GUI", 472, 188);Create GUI Window with the width of 472 and height of 188

$Button_1 = GuiCtrlCreateButton("Exit", 10, 130, 130, 50);Button_1 is the Exit Button
$Button_2 = GuiCtrlCreateButton("Execute Script", 250, 100, 210, 80); Button_2 is the Execute Script function

GuiSetState()
While 1;your LOOP
    $msg = GuiGetMsg();retrieves the button or control that was pressed
    Select; starts a case statement
    Case $msg = $GUI_EVENT_CLOSE;case statement, its like an if statement but better when you have alot of statements
    ExitLoop; If the program is exited it will exit the loop.
Case $msg = $Button_1
    ExitLoop;Exits the Loop
Case $msg = $Button_2
    ExecuteScript(); goes to the Execute Script function
    EndSelect; ends the case statements
WEnd

Func ExecuteScript();Creats the Execute Script Function
;Your Code
Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("Heyheyheyheyheyheyheyheyhey.")
WinClose("Untitled - Notepad")
WinWaitActive("Notepad", "The text in the Untitled file has changed")
Send("!n")
EndFunc

Share this post


Link to post
Share on other sites

nope... just run the code that you wrote and see how many times it runs. :-)

i don't get it...

would'nt it be logical for

1 to 2 make it loop once?

because 2-1 = 1

not trying to argue, its just a bit mind boggeling...

Share this post


Link to post
Share on other sites

i don't get it...

would'nt it be logical for

1 to 2 make it loop once?

because 2-1 = 1

not trying to argue, its just a bit mind boggeling...

If that's mind boggeling ... look out!! :o ... just run the 2 loops below.

For $i = 1 To 2
    MsgBox(0, 'Test', $i)
Next

For $x = 1 To 1
    MsgBox(0, 'Test2', $x)
Next

[center]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.[/center]

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