Davie Posted December 18, 2017 Share Posted December 18, 2017 Hi Guys , I only started playing with AutoIT yesterday and Im rether enjoying myself. I'm a little unsure how to handle this loop or change in a for next to stop at the end of file. Just now the csv has one line but it loops endlessly on the single entry in the csv. so... #include <IE.au3> #include <MsgBoxConstants.au3> #include <file.au3> #include <array.au3> ;get the csv $Line=1 $path="F:\logins.csv" ;readthe csv $String=FileReadLine($path,$Line) ;if theres a problem If $String="" Then MsgBox($MB_SYSTEMMODAL, "Fail", "Cant get anything from the file", 2) ;start the read using col 2,3,4 of the row.Output to messagebox to validate While 1 $Line+=1 $Snam=StringSplit($String, ",") MsgBox(0,"","Server : " & $Snam[1] & @CRLF & "User : " & $Snam[3] & @CRLF & "Pass : " & $Snam[4]) ;now go do some other things with Snam1 Snam2 Snam4 WEnd Im not clever enough yet to manipulate a for/next or some kind of better eof check... Any help appreciated , and thanks in advance... Davie. Link to comment Share on other sites More sharing options...
SlackerAl Posted December 18, 2017 Share Posted December 18, 2017 (edited) Feast your eyes on this: I would recommend reading it into a array first (the last option above). Reading individual lines is not very efficient. Edit: For your reference, the error in your code is that you increment the $Line count, but you don't read in a new string within your loop. Edited December 18, 2017 by SlackerAl Problem solving step 1: Write a simple, self-contained, running, replicator of your problem. Link to comment Share on other sites More sharing options...
Developers Jos Posted December 18, 2017 Developers Share Posted December 18, 2017 You are reading just line 1 of the CSV and I don't see anywhere in the code that you read subsequent lines from the file. There are UDF's available to read CSV files into an array which probably will make your life much easier... just search for those. 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...
SlackerAl Posted December 18, 2017 Share Posted December 18, 2017 You can also use _FileReadToArray with a delimiter to split into a multi-dimensional array. Which might be fun. Problem solving step 1: Write a simple, self-contained, running, replicator of your problem. Link to comment Share on other sites More sharing options...
Davie Posted December 18, 2017 Author Share Posted December 18, 2017 Thanks guys these are all ace! I think Ill have to go to MD array as an example line will be Blue,Red,Orange,White and I will have to use individual values. Ill mess around now - but thanks again!!! Link to comment Share on other sites More sharing options...
Davie Posted December 18, 2017 Author Share Posted December 18, 2017 Guys , could you maybe help here quickly: #include <Array.au3> #include <File.au3> Local $aInput $file = "F:\logins.csv" _FileReadToArray($file, $aInput, Default, ",") _ArrayDisplay($aInput) For $i = 1 to UBound($aInput) -1 MsgBox (0,'',$aInput[1][$i]) MsgBox (0,'',$aInput[2][$i]) MsgBox (0,'',$aInput[3][$i]) Next Message boxes are giving Col 1 row 1 , col 1 , row 2 Col 1 row 3. I would dance the dance of joy if it was returning Row 1 col 1 , row 1 col 2 , row 1 col 3 next Row 2 col 1 , row 2 col 2 , row 2 col 3 next etc AM I far off it? Link to comment Share on other sites More sharing options...
SlackerAl Posted December 18, 2017 Share Posted December 18, 2017 #include <Array.au3> #include <File.au3> Local $aInput $file = "F:\logins.csv" _FileReadToArray($file, $aInput, Default, ",") _ArrayDisplay($aInput) For $i = 1 to UBound($aInput) -1 MsgBox (0,'',$aInput[$i][0]) MsgBox (0,'',$aInput[$i][1]) MsgBox (0,'',$aInput[$i][2]) MsgBox (0,'',$aInput[$i][3]) Next Better? Earthshine 1 Problem solving step 1: Write a simple, self-contained, running, replicator of your problem. Link to comment Share on other sites More sharing options...
Davie Posted December 18, 2017 Author Share Posted December 18, 2017 Can you see me happy dancing SlackerAl!! Its sheer happy feet then I released I didn't understand the basic structure and I kinda tripped. Moving $I - can you spare a sec to explain whats being asked for in your example compared to mine? Thanks so much for helping. Works like a dream. Link to comment Share on other sites More sharing options...
Earthshine Posted December 18, 2017 Share Posted December 18, 2017 (edited) basically, the i counter is the row iterator, you need to study this link first. https://www.autoitscript.com/wiki/Arrays Edited December 18, 2017 by Earthshine My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
SlackerAl Posted December 18, 2017 Share Posted December 18, 2017 (edited) Imagine Your file: Apple,,,green Banana,yellow,, Minion,yellow,blue,, Your array [Col 0] [Col 1] [Col 2] [Col 3] [Row 1] Apple null null green [Row 2] Banana yellow null null [Row 3] Minion yellow blue null You can see col indexes and row indexes, any two indexes give you a position, e.g. 2,1 would be yellow, like plotting x, y on a map. (except row index first) Row 0 stores some info about the array by default, so forget it for now. So by putting $i first I lock the row we are looping to one $i value and I have hand coded in each column index (you would make this a second loop if you were keen). Edited December 18, 2017 by SlackerAl minor grammar Problem solving step 1: Write a simple, self-contained, running, replicator of your problem. 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