Jump to content
Sign in to follow this  
Timo

csv-file to list

Recommended Posts

Timo

Hello,

I want to read the data from a csv-file and show it in a list.

That's my code:

$myedit = GUICtrlCreateList ("", 500,50,400,500)

$adressfile = FileOpen("adress.dat",1)

While 1

$line = FileReadLine ($adressfile)

If @error = -1 Then exitloop

GUICtrlSetData($myedit,$line)

Wend

FileClose($adressfile)

I have a lot of trouble with this, e.g. I cant use 1 in FileOpen, only 0 is o.k.

Could someone please give me a short example how to do it the right way?

Thanks,

Timo


Bye...,Timo

Share this post


Link to post
Share on other sites
PerryRaptor

Try this...

$resource = FileOpen("resource.emp", 0)
If $resource = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf
While 1
    $line = FileReadLine($resource)
    If @error = -1 Then ExitLoop
    If FileExists($line) Then 
    ContinueLoop
    EndIf
Wend
FileClose($Resource)

Share this post


Link to post
Share on other sites
Timo

No, that doesn't solve the problem.

This is the code with the GUI-part:

$mylist = GUICtrlCreateList ("", 500,50,400,500)
$resource = FileOpen("adress.dat", 0)
If $resource = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf
While 1
    $line = FileReadLine($resource)
    If @error = -1 Then ExitLoop
    If FileExists($line) Then
    ContinueLoop
    GUICtrlSetData($mylist,$line) 
    EndIf
Wend
FileClose($resource)

The file which I want to open is a csv-file with the ";" as separator. Could this be the problem?


Bye...,Timo

Share this post


Link to post
Share on other sites
PerryRaptor

Checkout this article...

Filling Arrays from files

Excel.csv 2 AutoIT Arrays

Your csv file needs to be converted to an AutoIT Array

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  

×