How Create an Array from .CSV file ?

How Create an Array from .CSV file ?

Postby shri_fwh » Sun Aug 04, 2019 6:19 pm

Dear All ,

I want to create an array from .CSV file. any Function / Class for this ?

Please provide some sample code. Thanks in advance...!

Thanks
Shridhar
Thanks
Shridhar
FWH 19.12, BCC 7 32 bit, MariaDB
shri_fwh
 
Posts: 301
Joined: Mon Dec 07, 2009 2:49 pm

Re: How Create an Array from .CSV file ?

Postby ukoenig » Mon Aug 05, 2019 7:23 am

Shridhar,

can You show some lines from the top that we know the structure
A solution can be to create a DBF from the CSV-file and next using -> DBFTOARRAY

About some infos working with CSV
viewtopic.php?f=3&t=25043&p=155953&hilit=dbfcsv#p155953

About DBFTOARRAY
viewtopic.php?f=3&t=36678&p=218808&hilit=dbftoarray#p218808

A CSV - structure
Image

regards
Uwe :?:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: How Create an Array from .CSV file ?

Postby shri_fwh » Mon Aug 05, 2019 10:47 am

Hi Uwe ,

the .CSV file format will be similar as given below, it is simply invoice data. it has three segments 1) header 2) detail 3) footer.

Code: Select all  Expand view

H,ABC CO.,08052019, INV00031
D,10210,CROCIN TAB , 10, 30.00, 300, 10.00,10.00,320.00
D,21205,AMLOX TAB  , 10, 20.00, 300, 10.00,10.00,220.00
D,21535,CFLOX TAB  , 10, 10.00, 300, 10.00,10.00,120.00
F,30,30,660.00

 


Thanks
Shridhar
Thanks
Shridhar
FWH 19.12, BCC 7 32 bit, MariaDB
shri_fwh
 
Posts: 301
Joined: Mon Dec 07, 2009 2:49 pm

Re: How Create an Array from .CSV file ?

Postby ukoenig » Mon Aug 05, 2019 11:29 am

Does it mean that You need a array from the data-area ?
because a defined header and footer is not a normal CSV-file-structure
created from a DBF

Code: Select all  Expand view

aData := { { 10210,CROCIN TAB , 10, 30.00, 300, 10.00,10.00,320.00 }, ;
           { 21205,AMLOX TAB  , 10, 20.00, 300, 10.00,10.00,220.00 }, ;
           { 21535,CFLOX TAB  , 10, 10.00, 300, 10.00,10.00,120.00 } }
 


regards
Uwe :?:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: How Create an Array from .CSV file ?

Postby shri_fwh » Mon Aug 05, 2019 1:43 pm

Hi Uwe ,

Need 3 different arrays to process invoice data into our database.

Looking for a function which returns an array (single dim) for each record during .CSV line read then I can copy /add record into relevant main array

Thanks
shridhar
Thanks
Shridhar
FWH 19.12, BCC 7 32 bit, MariaDB
shri_fwh
 
Posts: 301
Joined: Mon Dec 07, 2009 2:49 pm

Re: How Create an Array from .CSV file ?

Postby nageswaragunupudi » Thu Aug 08, 2019 12:58 am

Code: Select all  Expand view
aData := HB_ATokens( cCsv, CRLF )
AEval( aData, { |c,i| aData[ i ] := HB_ATokens( c, "," ) } )
 


All elements of the array are untrimmed character values. You need to convert them into the required data type yourself.

Image
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: How Create an Array from .CSV file ?

Postby shri_fwh » Thu Aug 08, 2019 5:44 am

Dear Rao Sir ,

Simple and Excellent solution ...! Thanks a lot ...!

Just one question on the variable cCsv ,

Shall I use below method to read entire .CSV file and copy data into cCsv variable or any other function/logic ? please guide for the same.

Code: Select all  Expand view

local cCSVFile := "purcbill.csv"
local cCsv

oFile  := TTxtFile():New( cCSVFile )
oFile:GoTop()
Do while !oFile:Eof()
    cCsv := cCsv  + oFile:ReadLine()
    oFile:Skip()
Enddo


aData := HB_ATokens( cCsv, CRLF )
AEval( aData, { |c,i| aData[ i ] := HB_ATokens( c, "," ) } )

 


Thanks
Shridhar
Thanks
Shridhar
FWH 19.12, BCC 7 32 bit, MariaDB
shri_fwh
 
Posts: 301
Joined: Mon Dec 07, 2009 2:49 pm

Re: How Create an Array from .CSV file ?

Postby nageswaragunupudi » Thu Aug 08, 2019 6:44 am

local cCSVFile := "purcbill.csv"
local cCsv

oFile := TTxtFile():New( cCSVFile )
oFile:GoTop()
Do while !oFile:Eof()
cCsv := cCsv + oFile:ReadLine()
oFile:Skip()
Enddo


Instead of the above six lines of code,
Code: Select all  Expand view

cCsv := MEMOREAD( cCsvFile )
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: How Create an Array from .CSV file ?

Postby shri_fwh » Thu Aug 08, 2019 7:58 am

Dear Rao Sir ,

Supper..! Thanks a lot once again...!


Thanks
Shridhar
Thanks
Shridhar
FWH 19.12, BCC 7 32 bit, MariaDB
shri_fwh
 
Posts: 301
Joined: Mon Dec 07, 2009 2:49 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 47 guests