Sign in to follow this  
Followers 0
McDope

Readin a CSV for n00bs :P

5 posts in this topic

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 :lmao:

plz point me in the right direction or even better can someone make such func for me plz?


Share this post


Link to post
Share on other sites



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 :lmao:

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

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I already opened the file and read all lines into an array but now i dont unterstand how to use StringSplit :lmao:

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 by McDope

Share this post


Link to post
Share on other sites

I already opened the file and read all lines into an array but now i dont unterstand how to use StringSplit :lmao:

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"

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

A Friend helped me with it... now it works....

if someone interested in the code:

#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

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0