Page 1 of 1
Posted: Wed Oct 23, 2002 3:15 am
by BackupUser
Restored from previous forum. Originally posted by scurrier.
an easy way to load a CSV file example:
file name sean.csv
sean,currier,33,7-23-69
is in the file
commands
opencsv(1,"sean.csv")
readcsvs (1,first$,last$,age,date$)
and maybe a writecsv would be great too
thanks
Sean
Posted: Wed Oct 23, 2002 6:27 pm
by BackupUser
Restored from previous forum. Originally posted by Andre.
An easy way to do this (not tested):
Code: Select all
Structure person
FirstName$
Name$
Age.b
Date$
EndStructure
NewList Persons.person()
If ReadFile(0,"sean.csv")
Repeat
a$=ReadString()
AddElement(Persons())
Persons()\FirstName$=StringField(a$,1,",")
Persons()\Name$=StringField(a$,2,",")
Persons()\Age=Val(StringField(a$,3,","))
Persons()\Date$=StringField(a$,4,",")
Until Eof(0)
CloseFile(0)
EndIf
; "sean.csv" file must look like:
; sean,currier,33,7-23-69
; ....
The Write function should be no problem too

This way I always use lots of my csv files in an absolute flexible way...
Regards
André
*** German PureBasic Support ***
Posted: Thu Oct 24, 2002 11:39 am
by BackupUser
Restored from previous forum. Originally posted by fred.
Yes, the StringField() function is the way to go, and with a for/next it's nearly immediate.
Fred - AlphaSND
Posted: Thu Oct 24, 2002 11:15 pm
by BackupUser
Restored from previous forum. Originally posted by scurrier.
Thanks
This helps a lot.
Hay Fred how about the remstart and remend in the next version?
you could do it like in C
\\ starts the rem and // ends the rem