Can I use the for loop to write 9 rows at the time?

I am writing to CSV and it goes well, but there is a lot of data I need to generated.
So I tried the for loop. But it writes and overwrites on the same first row instead of giving me 9 rows populated with individual data.

void SaveToFile ()

{ table.clearRows();
  TableRow newRow = table.addRow();
   newRow.setInt("MACH ID", table.getRowCount() - 1);
   for (int i=1; i<=9; i++)
 {
  newRow.setInt("MACH ID", i);
  newRow.setInt("CUMM UPTIME", CummUp[i]);
  newRow.setInt("CYCLES TODAY", Cycles[i]);
  newRow.setString("TIME", TimeStamp);
  //newRow.setString("DATE", DateStamp);
 }
  ////////////////////////

println("ROW COUNT= " + table.getRowCount()); 

  Filename = "/data/"+"Infinity_Report_"+DateStamp + ".csv"; //DateStamp
  saveTable(table, Filename);
  //println("Settings Saved");
  
} 

What to do?
Thanks 
Mitch

move this after the for…{

AND

   newRow.setInt("MACH ID", table.getRowCount() - 1);

delete this.

but KEEP:

 newRow.setInt("MACH ID", i);

Remark

arrays usually start with 0, not 1, check your for-loop

1 Like

Yey, that worked…

Thanks , In my case I have to start with 1.

Danke Schoon

1 Like

Since you’re so good with arrays, etc…
I am trying to get a time stamp when a condition from the serial happens and it works for a min, then I get a nullPointer.
Any ideas?

 if ( list.length >=2 )
        {
          Mach_ID= int (list [0]);
          LastUptime= int(trim(list [1]));

          if (Mach_ID == 1)
            {CummUp [1] = (CummUp [1]+ LastUptime)/1000;
            Cycles [1] = (Cycles[1]+1);
            TimeStampArrFun(1);

            }

//// then the function
void TimeStampArrFun(int Mach_ID)
{

  sec = second();  // Values from 0 - 59
  min = minute();  // Values from 0 - 59
  hrs = hour();    // Values from 0 - 23
  day = day();    // Values from 1 - 31
  mo = month();  // Values from 1 - 12
  yr = year(); 


  String S = str(sec);  // Values from 0 - 59
  String M = str(min);
  String H = str(hrs);  // Values from 0 - 59
  String D = str(day);// Values from 0 - 59
  String MO = str(mo);  // Values from 0 - 59
  String Y = str(yr);// Values from 0 - 59

  TimeStampArr[Mach_ID] = H+":"+ nf(min,2)+":"+ nf(sec,2) +" ";
  println (Mach_ID  +"Stamp "+TimeStampArr[Mach_ID]);
}

What am I doing wrong?

The array is defined in the setup as :
String []TimeStampArr;

Also I tried to write the function as a String Arrray etc… trying to return the time stamp but it did not work out…

Thanks again
Mitch

I assume that you write over the end of the List

TimeStampArr

Like when you gave it an length of 500 when you try t
write element 501 it crashes

you don’t really need an array here

A simple string would be sufficient

Actually I need the array, there are 10 different time stamps.
The probelm was in declaring the array in the definition.
I tried the easy
String []TimeStampArr;
but it did not work, so I had to go the long way:
String TimeStampArr[]= {" ", " ", " ", " ", " ", " ", " ", " ", " ", " "};// 10 vals

Now it works. Lots more code…

Thanks

2 Likes