JohnnyDepth Posted February 27, 2016 Posted February 27, 2016 Hi all, I have been playing around with AutoIt for a couple weeks now, just making random things for fun. There is one thing I cannot wrap my head around for the life of me.. Here is what I am wanting to do: I have a csv file with this following data/columns: Hey,Hey1,Hey2,Hey3 Hello,Hello1,Hello2,Hello3 Hi,Hi1,Hi2,Hi3 (let's say this csv file is located C:\Test Folder\Test.csv) So the csv is three rows(for this example) and has four columns. I cannot figure out how to get this data out and store it into an array that I can use to type each column into 4 different word docs that are open. I do not need help with moving the mouse to each word doc, but i just don't know how to get the data out, put it into an array. Once I have the data in an array, I know I can figure out how to loop through, but getting to that point is my problem. Any help would be much appreciated.
AutoBert Posted February 27, 2016 Posted February 27, 2016 Just use _FileReadToArray: #include <File.au3> #include <Array.au3> Dim $aCSV[1] _FileReadToArray('test.csv', $aCSV,Default,',') _ArrayDisplay($aCSV)
JohnnyDepth Posted February 27, 2016 Author Posted February 27, 2016 Thanks! Will that bring in all 4 columns of the csv file? How do I 'sendkey' each column individually after it has been stored in the array?
AutoBert Posted February 27, 2016 Posted February 27, 2016 4 hours ago, JohnnyDepth said: Thanks! Will that bring in all 4 columns of the csv file? Yes, when your CSV is named test.csv or you change script to your CSV-name. Just test and see: 4 hours ago, JohnnyDepth said: How do I 'sendkey' each column individually after it has been stored in the array? Don't understand, please be more specific about your intention.
JohnnyDepth Posted February 27, 2016 Author Posted February 27, 2016 4 hours ago, AutoBert said: Don't understand, please be more specific about your intention. Sorry. I'd like to take the data in an array and type it into certain fields of a website. So i would want to type column one into a text box field on a website, then column two may be in another text box on a different page of the same website. Same with column 3 and 4. I know how to do everything in between such as moving the mouse and waiting for pages to load, but just inserting the individual columns from the csv is what i need help with.
AutoBert Posted February 27, 2016 Posted February 27, 2016 I am no native English speaker so please read Language Reference - Variables specialy Arrays, i hope this example sending each elemnt from the array to NotePad helps a little bit: #include <File.au3> #include <Array.au3> Dim $aCSV[1] _FileReadToArray('test.csv', $aCSV, Default, ',') _ArrayDisplay($aCSV) ; Run Notepad with the window maximized. Local $iPID = Run("notepad.exe", "", @SW_SHOWMAXIMIZED) ; Wait 10 seconds for the Notepad window to appear. $hWnd = WinWait("[CLASS:Notepad]", "", 10) For $iRows = 1 To $aCSV[0][0] ;starting in row 1 (row 0 contains dimensions info For $iCols = 0 To $aCSV[0][1] - 1 ;starting in col 0 ControlSetText($hWnd, "", "Edit1", 'Row ' & $iRows & '|Col ' & $iCols & ': ' & $aCSV[$iRows][$iCols] & @CRLF) Sleep(2000) Next ;col Next ;row ;single element row 2 | col 3 ControlSetText($hWnd, "", "Edit1", @CRLF & 'row 2 | col 3: ' & $aCSV[2][3] & @CRLF) ; Display the text of the edit control. ; Close the Notepad window using the handle returned by WinWait. WinClose($hWnd)
JohnnyDepth Posted February 28, 2016 Author Posted February 28, 2016 Thanks for all your help autobert! Question, wouldn't the $aCSV[1] need to be $aCSV[3] (assuming it is zero based) since there are four entries per row in the CSV?
iamtheky Posted February 28, 2016 Posted February 28, 2016 (edited) For $iRows = 1 To $aCSV[0][0] ;For $iRows = 1 to the Row Count that _FRTA put in row 0 column 0 (making the useful part of the array 1-based) For $iCols = 0 To $aCSV[0][1] - 1 ;For $iCols = 0 to the Column Count that _FRTA put in row 0 column 1 minus 1 (because columns still start at 0) i assume you mean here, because $aCSV is not a 1D array, hopefully those comments help. Edited February 28, 2016 by iamtheky ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
JohnnyDepth Posted February 28, 2016 Author Posted February 28, 2016 10 hours ago, iamtheky said: For $iRows = 1 To $aCSV[0][0] ;For $iRows = 1 to the Row Count that _FRTA put in row 0 column 0 (making the useful part of the array 1-based) For $iCols = 0 To $aCSV[0][1] - 1 ;For $iCols = 0 to the Column Count that _FRTA put in row 0 column 1 minus 1 (because columns still start at 0) i assume you mean here, because $aCSV is not a 1D array, hopefully those comments help. I apologize for the dumb questions, but what does _FRTA mean in your comments?
iamtheky Posted February 28, 2016 Posted February 28, 2016 FileReadToArray ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
JohnnyDepth Posted February 28, 2016 Author Posted February 28, 2016 Got it to work perfectly, thanks again for all the help! For those curious, here is the code: expandcollapse popup#include <File.au3> #include <Array.au3> Global $aCSV[1] Global $intCount = 0 Global $intRow = 0 Global $intCol = 0 Global $intLineCount = 0 _FileReadToArray("C:\Test Folder\Test CSV.csv", $aCSV, Default, ",") $intLineCount = _FileCountLines("C:\Test Folder\Test CSV.csv") - 1 While $intCount <= $intLineCount $intCount = $intCount + 1 ;$intRow = $intCount MouseClick("primary",63,16,1) Send($aCSV[$intRow+$intCount][$intCol]) Send("{ENTER}") Sleep(1000) MouseClick("primary",301,16,1) Send($aCSV[$intRow+$intCount][$intCol+1]) Send("{ENTER}") Sleep(1000) MouseClick("primary",532,16,1) Send($aCSV[$intRow+$intCount][$intCol+2]) Send("{ENTER}") Sleep(1000) WEnd _ArrayDisplay($aCSV)
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