`prev Menu next`

CSV File
On this BASIC, internal record type files are CSV files, which are commonly used on spreadsheets.
One line of a CSV file is one record of an internal record type file.
That is, one execution of a WRITE or READ statement carries out output or input of one line of a CSV file.
Example.
Outputs data on arrays declared with `DIM s$(10), h(10), w(10)` to a CSV file.
The file output can be read as a table of 3 columns, 10 rows in spreadsheets.

     OPEN #1:NAME "A:DATA.CSV",RECTYPE INTERNAL
     ERASE #1
     FOR i=1 TO 10
        WRITE #1:s$(i),h(i),w(i)
     NEXT i
     CLOSE #1

Conversely, the following program reads CSV table data of 3 columns, 10 rows into BASIC.

     DIM s$(10), h(10), w(10)
     OPEN #1:NAME "A:DATA.CSV",RECTYPE INTERNAL
     FOR i=1 TO 10
        READ #1:s$(i),h(i),w(i)
     NEXT i
     CLOSE #1

RECTYPE CSV (Original enhancement)
When an originally enhanced syntax RECTYPE CSV is written, array input and output are changed to be suited to cooperation with spreadsheet software.
For example, when an array A is defined in DIM A(10,4), the following generates 10 lines each of which has 4 numeric values separated by commas.

     OPEN #1:NAME "A:DATA.CSV",RECTYPE CSV
     ERASE #1
     MAT WRITE #1:A
     CLOSE #1

Furthermore, the following loads numeric data recorded with that form to the array.

     OPEN #1:NAME "A:DATA.CSV",RECTYPE CSV
     MAT READ #1:A
     CLOSE #1

Note. RECTYPE CSV is the same as RECTYPE INTERNAL if no array input or output is executed.