allen2111 Posted May 6, 2015 Share Posted May 6, 2015 (edited) Hi, I am very new to AutoIt. I want to make a script that performs some actions and then loops 100 times. Each time I want it to increment a file name in two locations. So "file1.txt" would become "file2.txt"..."file100.txt"I was able to make the base scripts but having trouble with the incrementing.I also found this http://www.autoitscript.com/forum/topic/77153-loop-through-files-in-directory/but adapting it to my scripts has been futile.any help is appreciated.expandcollapse popup#region --- Au3Recorder generated code Start (v3.3.9.5 KeyboardLayout=A0000409) --- #region --- Internal functions Au3Recorder Start --- Func _Au3RecordSetup() Opt('WinWaitDelay',100) Opt('WinDetectHiddenText',1) Opt('MouseCoordMode',0) Local $aResult = DllCall('User32.dll', 'int', 'GetKeyboardLayoutNameW', 'wstr', '') If $aResult[1] <> 'A0000409' Then MsgBox(64, 'Warning', 'Recording has been done under a different Keyboard layout' & @CRLF & '(A0000409->' & $aResult[1] & ')') EndIf EndFunc Func _WinWaitActivate($title,$text,$timeout=0) WinWait($title,$text,$timeout) If Not WinActive($title,$text) Then WinActivate($title,$text) WinWaitActive($title,$text,$timeout) EndFunc _AU3RecordSetup() #endregion --- Internal functions Au3Recorder End --- _WinWaitActivate("LTspice IV - 20150505 KED Model with Flexible Current Source.asc","20150505 KED Model w") MouseClick("right",631,622,1) _WinWaitActivate("Independent Current Source - I1","PULSE(I1 I2 Tdelay T") MouseClick("left",291,190,1) _WinWaitActivate("Piecewise Linear File","Files of &type:") MouseMove(147,527) MouseDown("left") MouseMove(65,527) MouseUp("left") Send("file1.txt") MouseClick("left",609,531,1) _WinWaitActivate("Independent Current Source - I1","PULSE(I1 I2 Tdelay T") MouseClick("left",540,442,1) _WinWaitActivate("LTspice IV - 20150505 KED Model with Flexible Current Source.asc","20150505 TED Model w") MouseClick("left",143,65,1) MouseClick("left",126,123,1) _WinWaitActivate("LTspice IV - 20150505 KED Model with Flexible Current Source","20150505 TED Model w") MouseClick("left",30,39,1) MouseClick("left",109,254,1) _WinWaitActivate("Select Traces to Export","Select Waveforms to ") MouseClick("left",314,72,1) _WinWaitActivate("Save As","Save as &type:") MouseClick("left",310,47,1) MouseClick("left",54,122,2) MouseClick("left",57,100,2) MouseMove(341,525) MouseDown("left") MouseMove(72,523) MouseUp("left") Send("file1.txt") MouseClick("left",610,522,1) _WinWaitActivate("Select Traces to Export","Select Waveforms to ") MouseClick("left",315,316,1) #endregion --- Au3Recorder generated code End --- Edited May 30, 2015 by allen2111 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 6, 2015 Moderators Share Posted May 6, 2015 allen2111,Welcome to the AutoIt forums.You need to put the code into a loop - look at For...Next...Step in the Help file. Then for each pass you can use the loop counter to increment the filename. Here is a short example to show the principle:#include <MsgBoxConstants.au3> ; Just 10 passes for this example For $i = 1 To 10 ; Your code runs here to get the data ; Create the filename - note the use of StringFormat to force leading 0s so the files sort correctly $sFileName = "File" & StringFormat("%03i", $i) & ".txt" ; Just to show what was produced MsgBox($MB_SYSTEMMODAL, "Filename", $sFileName) ; And here you would use FileWrite to save the file NextPlease ask if anything is unclear.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
allen2111 Posted May 30, 2015 Author Share Posted May 30, 2015 M23,I replaced the "; Your code runs here to get the data". I think I did something wrong because I am getting errors.I attached a screenshot so you could see the error. Link to comment Share on other sites More sharing options...
Developers Jos Posted May 30, 2015 Developers Share Posted May 30, 2015 You cannot have a Func-EndFunc in a For-Next loop.Jos 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 More sharing options...
allen2111 Posted May 30, 2015 Author Share Posted May 30, 2015 (edited) Jos,Thank you. I do not know enough about autoit to remedy the code. I attached the full code below. Can you suggest how I can change it to make it work?expandcollapse popup#include <MsgBoxConstants.au3> ; Just 10 passes for this example For $i = 1 To 10 #region --- Au3Recorder generated code Start (v3.3.9.5 KeyboardLayout=A0000409) --- #region --- Internal functions Au3Recorder Start --- Func _Au3RecordSetup() Opt('WinWaitDelay',100) Opt('WinDetectHiddenText',1) Opt('MouseCoordMode',0) Local $aResult = DllCall('User32.dll', 'int', 'GetKeyboardLayoutNameW', 'wstr', '') If $aResult[1] <> 'A0000409' Then MsgBox(64, 'Warning', 'Recording has been done under a different Keyboard layout' & @CRLF & '(A0000409->' & $aResult[1] & ')') EndIf EndFunc Func _WinWaitActivate($title,$text,$timeout=0) WinWait($title,$text,$timeout) If Not WinActive($title,$text) Then WinActivate($title,$text) WinWaitActive($title,$text,$timeout) EndFunc _AU3RecordSetup() #endregion --- Internal functions Au3Recorder End --- _WinWaitActivate("LTspice IV - 20150505 KED Model with Flexible Current Source","") MouseClick("right",740,623,1) _WinWaitActivate("Independent Current Source - I1","") MouseClick("left",287,185,1) _WinWaitActivate("Piecewise Linear File","") MouseMove(193,515) MouseDown("left") MouseMove(47,510) MouseUp("left") Send("file1.txt") MouseClick("left",562,518,1) _WinWaitActivate("Independent Current Source - I1","") MouseClick("left",537,433,1) _WinWaitActivate("LTspice IV - 20150505 KED Model with Flexible Current Source.asc","") MouseClick("left",148,64,1) MouseClick("left",91,123,1) _WinWaitActivate("LTspice IV - 20150505 KED Model with Flexible Current Source","") MouseClick("left",23,36,1) MouseClick("left",169,261,1) _WinWaitActivate("Select Traces to Export","") MouseMove(289,72) MouseDown("left") MouseMove(289,73) MouseUp("left") _WinWaitActivate("Save As","") MouseClick("left",323,49,1) MouseClick("left",83,122,2) MouseClick("left",93,101,2) MouseMove(346,516) MouseDown("left") MouseMove(50,497) MouseUp("left") Send("file1.txt") MouseClick("left",576,518,1) _WinWaitActivate("Select Traces to Export","") MouseClick("left",333,312,1) #endregion --- Au3Recorder generated code End --- #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.12.0 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here ; Create the filename - note the use of StringFormat to force leading 0s so the files sort correctly $sFileName = "File" & StringFormat("%03i", $i) & ".txt" ; Just to show what was produced MsgBox($MB_SYSTEMMODAL, "Filename", $sFileName) ; And here you would use FileWrite to save the file Next Edited May 30, 2015 by allen2111 Link to comment Share on other sites More sharing options...
Developers Jos Posted May 30, 2015 Developers Share Posted May 30, 2015 Then you will have to study a bit. .. Think it is important you understand the code when you want to use it.Start with moving your Func-EndFunc protions of code to the end of your script.Jos 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 More sharing options...
allen2111 Posted May 30, 2015 Author Share Posted May 30, 2015 Jos,Thanks. Good attitude. "Teach me to fish" rather than throw me a fish.I struggled with moving the functions to the bottom, had to leave behind the region stuff. The code now works as it did prior to moving the functions to the bottom.I am now working on getting the loop working.I moved this just above the functions#include <MsgBoxConstants.au3> ; Just 10 passes for this example For $i = 1 To 10and moved this just below the functions. I also tried moving the above code to the very top of the file and leaving the below code at the bottom.; Create the filename - note the use of StringFormat to force leading 0s so the files sort correctly $sFileName = "File" & StringFormat("%03i", $i) & ".txt" ; Just to show what was produced MsgBox($MB_SYSTEMMODAL, "Filename", $sFileName) ; And here you would use FileWrite to save the file Nextno joy. Same "next" errors as before plus a syntax error and "statement cannot be just an expression" Link to comment Share on other sites More sharing options...
Developers Jos Posted May 30, 2015 Developers Share Posted May 30, 2015 mmm.. though I was pretty explicit about not putting the Func-EndFunc inside of the For-Next loop Just move them both below the Next statement!Jos 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 More sharing options...
allen2111 Posted May 30, 2015 Author Share Posted May 30, 2015 I just got it going but looks like the loop code needs changes. Let me try some stuff and get back to you. Thanks. Link to comment Share on other sites More sharing options...
allen2111 Posted May 30, 2015 Author Share Posted May 30, 2015 The loop and the counter are working!! I have two of these statements "Send("file1.txt")"This is where Autoit inputs a file name. (you probably knew that).Do you know the syntax for making the "file1.txt" change to "file2.txt"... with the counter? Link to comment Share on other sites More sharing options...
allen2111 Posted May 30, 2015 Author Share Posted May 30, 2015 spoke to soon again. Got it "File" & StringFormat("%i", $i) & ".txt" Link to comment Share on other sites More sharing options...
Developers Jos Posted May 30, 2015 Developers Share Posted May 30, 2015 ... Just take your time to understand each step and you'll see you get there where you want to be.Next you really should check out au3info and see if you can use Controlxxxx commands in stead of the Send() commands build by au3recorder.Jos 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 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