kjpolker Posted October 10, 2009 Share Posted October 10, 2009 (edited) Okay now I was wondering if it is possible to loop just a select few of lines over and over for a selected amount of times (number is chosen in input box). For an example imagine I have this small script: #include <GUIConstants.au3> $Main = GUICreate("Example", 117, 117, 303, 219) $Input1 = GUICtrlCreateInput("0", 40, 40, 33, 21) $OK = GUICtrlCreateButton("OK", 40, 64, 33, 17, 0) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $OK WinActivate('[TITLE:Untitled - Notepad]') Send('This is a test') EndSwitch WEnd Okay now that is as far as I can go, now what I want this script to do is that the line that writes a sentance to notepad, gets repeated the amount of times in the input box. So lets say I insert the number "10", I hit the "OK" button and notepad pops up and types out the line "This is a test" 10 times. How can I do this? Thanks! Edited October 10, 2009 by kjpolker Link to comment Share on other sites More sharing options...
FuryCell Posted October 10, 2009 Share Posted October 10, 2009 Try using a for loop. HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code. Link to comment Share on other sites More sharing options...
Quual Posted October 10, 2009 Share Posted October 10, 2009 There are different types of loops here are 3 basic versions the While Wend loop $i = 0 While $i <= $Input1 Send('This is a test') $i += 1 WEnd the Do Until loop $i = 0 Do Send('This is a test') $i += 1 Until $i = $Input1 the For Next Loop For $i = 1 To $Input1 Send('This is a test') Next Link to comment Share on other sites More sharing options...
kjpolker Posted October 10, 2009 Author Share Posted October 10, 2009 I wasn't able to find out how to get this to work. I threw the loop script in the while and now when I launch the program it just spams the 'This is a test' in the input box. Link to comment Share on other sites More sharing options...
jebus495 Posted October 10, 2009 Share Posted October 10, 2009 (edited) I wasn't able to find out how to get this to work. I threw the loop script in the while and now when I launch the program it just spams the 'This is a test' in the input box. Local $banana Do $banana += 1 MsgBox("", "bananaz", "you have " & $banana & " bananaz") Until $banana > 9 ^ Example Here's what I would prolly do in your case. #include <GUIConstants.au3> $Main = GUICreate("Example", 117, 117, 303, 219) $Input1 = GUICtrlCreateInput("0", 40, 40, 33, 21) $OK = GUICtrlCreateButton("OK", 40, 64, 33, 17, 0) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $OK WinActivate('[TITLE:Untitled - Notepad]') WinWaitActive('[TITLE:Untitled - Notepad]') ;Waits for Notepad to be active. sendsomecrap() ;loop function EndSwitch WEnd Func sendsomecrap() Local $times ;declare this Do $times += 1 ;adds 1 to $times every time it loops. Sleep(100) ;don't wanna go too fast eh Send("This is a test" & @LF) ;@LF will put each "this is a test" on a new line Until $times = GUICtrlRead($Input1) ;compares $times to the value in the input box. when they are equal the loop will stop. EndFunc Edited October 10, 2009 by jebus495 Link to comment Share on other sites More sharing options...
kjpolker Posted October 10, 2009 Author Share Posted October 10, 2009 Local $banana Do $banana += 1 MsgBox("", "bananaz", "you have " & $banana & " bananaz") Until $banana > 9 ^ Example Here's what I would prolly do in your case. #include <GUIConstants.au3> $Main = GUICreate("Example", 117, 117, 303, 219) $Input1 = GUICtrlCreateInput("0", 40, 40, 33, 21) $OK = GUICtrlCreateButton("OK", 40, 64, 33, 17, 0) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $OK WinActivate('[TITLE:Untitled - Notepad]') WinWaitActive('[TITLE:Untitled - Notepad]') ;Waits for Notepad to be active. sendsomecrap() ;loop function EndSwitch WEnd Func sendsomecrap() Local $times ;declare this Do $times += 1 ;adds 1 to $times every time it loops. Sleep(100) ;don't wanna go too fast eh Send("This is a test" & @LF) ;@LF will put each "this is a test" on a new line Until $times = GUICtrlRead($Input1) ;compares $times to the value in the input box. when they are equal the loop will stop. EndFunc Thank you so much! my project is finally complete!!! I appreciate it. 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