hmdan2 Posted January 17, 2018 Share Posted January 17, 2018 Hello everyone, I am currently struggling. I'm a beginner in scripting, and I admit I have a limited understanding of how loops work. What I need to do is to automate a process in BrainVoyager that is otherwise done manually - 5 different files per each subject need to be selected. I have about 100 subjects to go through. What I'm trying to get my script to do is loop 100 times, and on each loop read and send a line from 5 different txt files (A,B,C,D,E). The txt files contain paths to different files for each subject. They look like this (only with 100 lines): D:\AutoIT\SUBJECT1\run_1\SUBJECT1_PA_run1.fmr D:\AutoIT\SUBJECT2\run_1\SUBJECT2_PA_run1.fmr So on loop 1, only the first lines (SUBJECT1) of all the 5 different txt files should be read and sent, loop 2 only the second lines (SUBJECT2), loop 3 only the 3rd (SUBJECT3)... The problem I'm having is that only the first loop does what I want. On the second loop only the second line from file E is read and sent, with the first lines of files A-D. How can I modify my script to do what I want? Is it even possible with this approach? Thank you a lot for your help in advance, I'm wandering around in the dark here. expandcollapse popup#include <MsgBoxConstants.au3> #include <File.au3> AutoItSetOption('MouseCoordMode',0) ; setting the WINDOW RELATIVE COORDINATE MODE AutoItSetOption('SendKeyDelay',5) ; setting the speed of typing and keys pressing to 0 (immidiately) $fileA = "D:\AutoIT\EPI\AutoIt_Parameter_Files\COPE_file_1.txt" $fileB = "D:\AutoIT\EPI\AutoIt_Parameter_Files\COPE_file_2.txt" $fileC = "D:\AutoIT\EPI\AutoIt_Parameter_Files\COPE_file_3.txt" $fileD = "D:\AutoIT\EPI\AutoIt_Parameter_Files\COPE_file_4.txt" $fileE = "D:\AutoIT\EPI\AutoIt_Parameter_Files\COPE_file_5.txt" ;;;;;;;;;; READING THE TXT FILES ;;;;;;;;;; FileOpen($fileA, 0) ; opening the .txt file Global $filenamesA[_fileCountLines($fileA)] For $ii = 1 to _fileCountLines($fileA) $filenamesA[$ii-1] = FileReadLine($fileA, $ii) Next fileClose($fileA) ; closing the .txt file FileOpen($fileB, 0) ; opening the .txt file Global $filenamesB[_fileCountLines($fileB)] For $ii = 1 to _fileCountLines($fileB) $filenamesB[$ii-1] = FileReadLine($fileB, $ii) Next fileClose($fileB) ; closing the .txt file FileOpen($fileC, 0) ; opening the .txt file Global $filenamesC[_fileCountLines($fileC)] For $ii = 1 to _fileCountLines($fileC) $filenamesC[$ii-1] = FileReadLine($fileC, $ii) Next fileClose($fileC) ; closing the .txt file FileOpen($fileD, 0) ; opening the .txt file Global $filenamesD[_fileCountLines($fileD)] For $ii = 1 to _fileCountLines($fileD) $filenamesD[$ii-1] = FileReadLine($fileD, $ii) Next fileClose($fileD) ; closing the .txt file FileOpen($fileE, 0) ; opening the .txt file Global $filenamesE[_fileCountLines($fileE)] For $ii = 1 to _fileCountLines($fileE) $filenamesE[$ii-1] = FileReadLine($fileE, $ii) Next fileClose($fileE) ; closing the .txt file ;;;;;;;;;; RUNNING THE LOOP ;;;;;;;;;; for $a= 0 To (UBound($filenamesa)-1) for $b= 0 To (UBound($filenamesb)-1) for $c= 0 To (UBound($filenamesc)-1) for $d= 0 To (UBound($filenamesd)-1) for $e= 0 To (UBound($filenamese)-1) Run("C:\Program Files (x86)\BrainVoyager\BrainVoyagerQX.exe") WinWait('Welcome') WinActivate('Welcome') Send('{ENTER}') ;;; open program WinWait('BrainVoyager QX') WinActivate('BrainVoyager QX') Send('{TAB DOWN}') Send('{ALT}') Send('{TAB UP}') Send('{LEFT 5}') Send('{DOWN 3}') Send('{ENTER 2}') Send($filenamesA[$a],1) Send('{TAB}{TAB}{SPACE}') Sleep(10) WinWaitActive("COPE plugin for EPI distortion correction") Send('{TAB 6}') Send('{ENTER}') Send($filenamesB[$b],1) Send('{TAB}{TAB}{SPACE}') Sleep(10) Send('{TAB 7}') Send('{ENTER}') Sleep(8000) Send('{RIGHT 2}') Send('{TAB 3}') Send('{ENTER}') Send($filenamesC[$c],1) Send('{ENTER}') Send('{SHIFTDOWN}') Send('{TAB 7}') Send('{SHIFTUP}') Send('{ENTER}') Send($filenamesD[$d],1) Send('{ENTER 2}') Send($filenamesE[$e],1) Send('{ENTER}') Send('{TAB 3}') Send('{ENTER}') Sleep(15000) ;;; close program Send('{ESC}') Send('{CTRLDOWN}') Send('{q}') Send('{CTRLUP}') Next Next Next Next Next Link to comment Share on other sites More sharing options...
BrewManNH Posted January 17, 2018 Share Posted January 17, 2018 This might be somewhat along the lines of what you're looking for. expandcollapse popup#include <MsgBoxConstants.au3> #include <File.au3> AutoItSetOption('MouseCoordMode', 0) ; setting the WINDOW RELATIVE COORDINATE MODE AutoItSetOption('SendKeyDelay', 5) ; setting the speed of typing and keys pressing to 0 (immidiately) $fileA = "D:\AutoIT\EPI\AutoIt_Parameter_Files\COPE_file_1.txt" $fileB = "D:\AutoIT\EPI\AutoIt_Parameter_Files\COPE_file_2.txt" $fileC = "D:\AutoIT\EPI\AutoIt_Parameter_Files\COPE_file_3.txt" $fileD = "D:\AutoIT\EPI\AutoIt_Parameter_Files\COPE_file_4.txt" $fileE = "D:\AutoIT\EPI\AutoIt_Parameter_Files\COPE_file_5.txt" $filenamesA = FileReadToArray($fileA) $filenamesB = FileReadToArray($fileB) $filenamesC = FileReadToArray($fileC) $filenamesD = FileReadToArray($fileD) $filenamesE = FileReadToArray($fileE) ;~ ;;;;;;;;;; READING THE TXT FILES ;;;;;;;;;; ;~ FileOpen($fileA, 0) ; opening the .txt file ;~ Global $filenamesA[_FileCountLines($fileA)] ;~ For $ii = 1 To _FileCountLines($fileA) ;~ $filenamesA[$ii - 1] = FileReadLine($fileA, $ii) ;~ Next ;~ FileClose($fileA) ; closing the .txt file ;~ FileOpen($fileB, 0) ; opening the .txt file ;~ Global $filenamesB[_FileCountLines($fileB)] ;~ For $ii = 1 To _FileCountLines($fileB) ;~ $filenamesB[$ii - 1] = FileReadLine($fileB, $ii) ;~ Next ;~ FileClose($fileB) ; closing the .txt file ;~ FileOpen($fileC, 0) ; opening the .txt file ;~ Global $filenamesC[_FileCountLines($fileC)] ;~ For $ii = 1 To _FileCountLines($fileC) ;~ $filenamesC[$ii - 1] = FileReadLine($fileC, $ii) ;~ Next ;~ FileClose($fileC) ; closing the .txt file ;~ FileOpen($fileD, 0) ; opening the .txt file ;~ Global $filenamesD[_FileCountLines($fileD)] ;~ For $ii = 1 To _FileCountLines($fileD) ;~ $filenamesD[$ii - 1] = FileReadLine($fileD, $ii) ;~ Next ;~ FileClose($fileD) ; closing the .txt file ;~ FileOpen($fileE, 0) ; opening the .txt file ;~ Global $filenamesE[_FileCountLines($fileE)] ;~ For $ii = 1 To _FileCountLines($fileE) ;~ $filenamesE[$ii - 1] = FileReadLine($fileE, $ii) ;~ Next ;~ FileClose($fileE) ; closing the .txt file ;;;;;;;;;; RUNNING THE LOOP ;;;;;;;;;; For $a = 0 To (UBound($filenamesA) - 1) ;~ For $b = 0 To (UBound($filenamesB) - 1) ;~ For $c = 0 To (UBound($filenamesC) - 1) ;~ For $d = 0 To (UBound($filenamesD) - 1) ;~ For $e = 0 To (UBound($filenamesE) - 1) Run("C:\Program Files (x86)\BrainVoyager\BrainVoyagerQX.exe") WinWait('Welcome') WinActivate('Welcome') Send('{ENTER}') ;;; open program WinWait('BrainVoyager QX') WinActivate('BrainVoyager QX') Send('{TAB DOWN}') Send('{ALT}') Send('{TAB UP}') Send('{LEFT 5}') Send('{DOWN 3}') Send('{ENTER 2}') Send($filenamesA[$a], 1) Send('{TAB}{TAB}{SPACE}') Sleep(10) WinWaitActive("COPE plugin for EPI distortion correction") Send('{TAB 6}') Send('{ENTER}') Send($filenamesB[$a], 1) Send('{TAB}{TAB}{SPACE}') Sleep(10) Send('{TAB 7}') Send('{ENTER}') Sleep(8000) Send('{RIGHT 2}') Send('{TAB 3}') Send('{ENTER}') Send($filenamesC[$a], 1) Send('{ENTER}') Send('{SHIFTDOWN}') Send('{TAB 7}') Send('{SHIFTUP}') Send('{ENTER}') Send($filenamesD[$a], 1) Send('{ENTER 2}') Send($filenamesE[$a], 1) Send('{ENTER}') Send('{TAB 3}') Send('{ENTER}') Sleep(15000) ;;; close program Send('{ESC}') Send('{CTRLDOWN}') Send('{q}') Send('{CTRLUP}') Next hmdan2 1 If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
kylomas Posted January 17, 2018 Share Posted January 17, 2018 Your loops are nested, consequently all of E is read before D, all of D is read before C and so on. Secondly , the way you are reading the files is wrong.. Can you post an example of the files? Ktlomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
hmdan2 Posted January 17, 2018 Author Share Posted January 17, 2018 Holy crap BrewManNH, that worked perfectly. You are a god. Thank you so much!! This is dumb question, but how do the $filenamesB, C, etc. appear in the loop even though only $filenamesA is specified in the For loop? I'd like to understand. Link to comment Share on other sites More sharing options...
BrewManNH Posted January 18, 2018 Share Posted January 18, 2018 I'm only using the size of the $filenamea array as the basis for the for loop. This presumes that b,c,d, and e are all the same size as A. Because they're all the same size, the elements of the array should be in identical positions in the array. This is a lot of assuming, but given the parameters it fits. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator 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