Trouble with saving to Table

I am trying to make an interface that would save grades for students. Then the data is saved to CSV.
In the first column I have the student ID (SID)- next to it are the grades.

What I wish for is that if I go back to the Student ID 202 for instance, and enter new grades, I wont have processing make a new row later, I can actually re-write the grades on row 2.

So is there a way to specify where in the spreadsheet I would be writing the rows?

Thanks a lot,

Here is my code:

void SaveToFile ()

{
  TableRow newRow = table.addRow();
 
  newRow.setInt("SID", SID);
  newRow.setInt("outline", outline);
  newRow.setInt("internal", internal);
    newRow.setInt("retention", retention);
  newRow.setInt("marginal", marginal);
  newRow.setInt("impression", impression);
  ////////////////////////
    newRow.setInt("surf", surf);
  newRow.setInt("margins", margins);
   newRow.setInt("occlusion", occlusion);
  newRow.setInt("contour", contour);
   newRow.setInt("lab", lab);

  
  saveTable(table, "data/YepuGrades.csv");
  println("Settings Saved");
1 Like

Processing.org/reference/Table_findRow_.html

1 Like

Thanks for the guidance. However, FindRow is finding a row in a table already written.
I am looking to write new rows, and re-write them over the old values.

Sorry, I am new.

Can you help?

Thanks

I think I’m confused. Do you want a new row, or not? I thought you wanted to edit an old row.

1 Like

I am sorry, maybe I wasnt clear.

I would want to re-write a row in a predetermined place.
So lets say the student 202 should always be on row 2 and when I change the grades, he’s new grades are written again on row 2.
Right now, a new row would be added. That means that he’ll have multiple entries on the sheet.
Thanks

Use findRow

Then you have a row object

Here you can change the old data

I understand the part about finding the row.
But then how do I write on that particular row?
If use " ```
newRow.setInt( etc

That would make me a new row at the bottom of the sheet.
Thanks

Table::findRow(), Table::getRow(), Table::addRow(), etc. methods all return a TableRow object. :stadium:

You then change that returned TableRow object using its own methods, not those from Table: :nerd_face:
Processing.org/reference/TableRow.html

1 Like

Exactly

Don’t use addRow obviously

Use findRow and then
row.setFloat(“mass”, 15.9994);
row.setString(“name”, “Oxygen”);

1 Like