# Create .csv file with data in a column (table)

**URL:** <https://discourse.processing.org/t/create-csv-file-with-data-in-a-column-table/40493>\
**Category:** Coding Questions\
**Created:** [January 6, 2023, 10:41pm UTC](https://discourse.processing.org/t/create-csv-file-with-data-in-a-column-table/40493 "2023-01-06T22:41:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fsdonato](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/fsdonato/32/18621_2.png) [@fsdonato](https://discourse.processing.org/u/fsdonato)\
**Post date:** [January 6, 2023, 10:41pm UTC](https://discourse.processing.org/t/create-csv-file-with-data-in-a-column-table/40493/1 "2023-01-06T22:41:20Z")

</div>

I’m writing a code that receives the value of a potentiometer at all times (float val\_pot2)  
I created a function to record these values in a table in .csv format  
I have the following problem: I am not able to save a new value in each line.  
What happens with my code is that the file is always saved with the last potentiometer value when I started recording.  
How can I solve this problem so that the file is formatted:  
Voltage  
1.12  
1.5  
2.0  
3.0  
4.0  
3.5  
3.0  
…

```auto
Table table;
void RECORD() {
   
  table = new Table();
  table.addColumn("Voltage");
  TableRow newRow = table.addRow();
  
   for(int k=0; k<10; k++) {
  table.addRow();
  newRow.setFloat("Voltage",val_pot2);
  saveTable(tabela, "data/new.csv");
  delay(10); 
   }
   
  }

```

 ![Sem título](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/1/8/1829df5006bf0c20c2d4e87f5f73fde62f8627f6.jpeg)

---

<div class="post-metadata">

**Author:** ![SomeOne](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/someone/32/8639_2.png) [@SomeOne](https://discourse.processing.org/u/SomeOne)\
**Post date:** [January 7, 2023, 6:15am UTC](https://discourse.processing.org/t/create-csv-file-with-data-in-a-column-table/40493/2 "2023-01-07T06:15:35Z")

</div>

Hi fsdonato,

Welcome to the forum.

Your function RECORD() creates each time a new table, so what ever was recorded on previous call is thrown away.

You don’t need a table object to store csv. CSV is a plain text file where you use a separator (usually comma but not always) to separate values on the row. In your case just opening a text file and adding new values to it might be enough.

You can do that with PrintWriter. Processing documentation has a nice example how to use it [createWriter() / Reference / Processing.org](https://processing.org/reference/createWriter_.html). In your case closing the file is different, but commands and logic is same.
