Hi there–so I am trying to write something that can input text and then store what is there to an array. Most of the array tutorials I have seen are about numeric data. Is it any different for storing text? Furthermore, is there a way to print out the array’s contents to verify that the data is actually in there, piece by piece? The documentation on this is very confusing.
I have the variables for this down but it’s where to go from there that gives me issues. I can do it for an individual string but the arrays confuse me.
Now for the next question–let’s say we need to store a name and address of someone. How can we store these under one person? For example, let’s say we have Bob and we need to associate the address we input, let’s just call it 1234 5th Street.
I have the basic basics down, now it’s just time for the next step with specific storage.
Show one person only on a screen with multiple lines
Show a form for one person where you can fill out his or her data. On sending the input text fields are copied into your table. That’s not totally easy since you have multiple fields for text but only one is selected. Only this changes when we type. Use mouse or tab to get to another text field.
You would only have one table that serves all 3 screens.
from workflow this should come first,
make your “data/mydata.csv” file with header first
( like in spreadsheet software OR notepad )
and test the loadTable defaults ( columncount , rowcount, select row and print all …)
String filename = "data/mydata.csv";
/*
id,name,street,town,code,
1,you,yourstreet,yourtown,1174,
0,me,mystreet,mytown,4711,
*/
Table mytable;
int tcols, trows, numcol = 0;
boolean dprint = true;
void get_tabledata() { // get tabledata from file
mytable = loadTable(filename, "header, csv");
tcols = mytable.getColumnCount();
trows = mytable.getRowCount();
if (dprint) {
println("total cols in table: "+tcols);
println("total rows in table: "+trows+", header line not counted ");
println("header: ");
for ( int i = 0; i < tcols; i++) println("headerline col: "+i+" "+ mytable.getColumnTitle(i));
for ( int j = 0; j < trows; j++) {
TableRow thisrow = mytable.getRow(j);
for ( int i = 0; i< tcols; i++) println("row "+j+ " col "+i+" "+mytable.getColumnTitle(i)+" : "+thisrow.getString(i));
}
}
}
void sort_tabledata() { // sort numerically a specific column
mytable.setColumnType(numcol, Table.INT);
mytable.sort(numcol);
if (dprint) {
println("list all rows column "+numcol+" _"+mytable.getColumnTitle(numcol)+"_ sorted by number");
for ( int i = 0; i < mytable.getRowCount(); i++ ) {
TableRow thisrow = mytable.getRow(i);
println("row "+i+" "+thisrow.getInt(numcol));
}
}
}
void save_tabledata() { // save to file
saveTable(mytable, filename, "csv");
println("and saved back to "+filename);
}
void setup() {
get_tabledata();
sort_tabledata();
save_tabledata();
exit();
}
this might not look so nice, as i not use the column names like thisrow.getString("name")
instead i use the column number 0…colcount
only because this code fits to all CSV with header structure
(ok besides the sort column 0 setting )