Jump to content

How do I make a script repeat?


bucky002
 Share

Recommended Posts

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?

Link to comment
Share on other sites

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
Link to comment
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
Edited by =sinister=
Link to comment
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
Link to comment
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..

Link to comment
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.

Link to comment
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
Link to comment
Share on other sites

  • Moderators

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

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