McDope Posted January 19, 2006 Share Posted January 19, 2006 Hi, i want to read in an CSV File with 3 values per line and this values should all put in a seperate array for "x", "y" and "bks". My Problem is that im new to this stuff and really dont know how to do this plz point me in the right direction or even better can someone make such func for me plz? Link to comment Share on other sites More sharing options...
blademonkey Posted January 19, 2006 Share Posted January 19, 2006 Hi, i want to read in an CSV File with 3 values per line and this values should all put in a seperate array for "x", "y" and "bks". My Problem is that im new to this stuff and really dont know how to do this plz point me in the right direction or even better can someone make such func for me plz?Look at Fileread() and Filereadline, then do a stringsplit. maye something like this: #include<file.au3> $file= "C:\path\file.csv" Fileopen($file) $numberoflines= _FileCountLines($file) for $j = 1 to $numberoflines $dataofcurrentline = Filereadline($file, $j) Next that should give you an idea of how to read in the data. Don't rely on this code too much as it is not specific to your scenario. You'll have to play around a little to manipulate the data. hope that helps. ---"Educate the Mind, Make Savage the Body" -Mao Tse Tung Link to comment Share on other sites More sharing options...
McDope Posted January 19, 2006 Author Share Posted January 19, 2006 (edited) I already opened the file and read all lines into an array but now i dont unterstand how to use StringSplit i mean i dont understand how to call stringsplit so that each value is put in an seperate array like in my first post... Edited January 19, 2006 by McDope Link to comment Share on other sites More sharing options...
seandisanti Posted January 19, 2006 Share Posted January 19, 2006 I already opened the file and read all lines into an array but now i dont unterstand how to use StringSplit i mean i dont understand how to call stringsplit so that each value is put in an seperate array like in my first post...StringSplit actually seperates a string into an array, with element 0 being the count of items in the array. like: $line = "one,two,three" $blah = StringSplit($line,",") ;$blah[0] = 3 ;$blah[1] = "one" ;$blah[2] = "two" ;$blah[3] = "three" Link to comment Share on other sites More sharing options...
McDope Posted January 19, 2006 Author Share Posted January 19, 2006 A Friend helped me with it... now it works.... if someone interested in the code: expandcollapse popup#include <Array.au3> #include <file.au3> ;==> START Choose and import CSV File $filename = FileOpenDialog("CSV wählen...", "", "CSV (*.csv)") $file = FileOpen($filename, 0) $l = _FileCountLines($filename) Dim $xArray[$l] Dim $yArray[$l] Dim $bksArray[$l] Dim $obiArray[$l] $avArray = _ArrayCreate($xArray, $yArray, $bksArray, $obiArray) $i=0 $j=0 ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf While 1 $chars = FileReadLine($file) If @error = -1 Then ExitLoop $array = StringSplit($chars, ";") ; _ArrayDisplay( $array, "Array" ) $xArray[$j]=$array[mod($i+1,4)] $yArray[$j]=$array[mod($i+1,4)+1] $bksArray[$j]=$array[mod($i+1,4)+2] $obiArray[$j]=$array[mod($i+1,4)+3] $i = $i + 4 $j = $j + 1 Wend ;_ArrayDisplay( $xArray, "xArray" ) ;_ArrayDisplay( $yArray, "yArray" ) ;_ArrayDisplay( $bksArray, "bksArray" ) ;_ArrayDisplay( $obiArray, "obiArray" ) FileClose($file) ;==> END Choose and import CSV File 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