question

Luis Gaytan avatar image
0 Likes"
Luis Gaytan asked Jason Lightfoot commented

OnReset Table keep a column logic

I want to keep "Model" & "ModelNumber" columns in a global table, but the logic OnReset delete all the rows that I dont want to delete, how can I keep these columns without erasing the "Delete All Rows" on the global table

1690406762707.png

Table current = param(1); //Data nodeTable current = param(1); //Data node
{ // ************* PickOption Start ************* //
/**Delete All Rows*/
/**\nDeletes all rows of the table, preserving the column headers*/
current.setSize(1, current.numCols);
} // ******* PickOption End ******* //


Table Boom_Sequence = Table("BoomSequence_3");


for(int h = 1 ; h<= Boom_Sequence.numRows ; h++)
{
if(Boom_Sequence[h]["Model"] == "Gavea30")
{
    Boom_Sequence[h]["ModelNumber"] = 1;
}
else if(Boom_Sequence[h]["Model"] == "Gavea36")
{
    Boom_Sequence[h]["ModelNumber"] = 2;
}
else if(Boom_Sequence[h]["Model"] == "PLA40")
{
    Boom_Sequence[h]["ModelNumber"] = 3;
}
else if(Boom_Sequence[h]["Model"] == "PLAHibrido")
{
    Boom_Sequence[h]["ModelNumber"] = 4;
}
else if(Boom_Sequence[h]["Model"] == "PLA36")
{
    Boom_Sequence[h]["ModelNumber"] = 5;
}
}


int Dr = Boom_Sequence[1][3];
int RS = Boom_Sequence[1][4];


Array x = Array(Dr);
Array y = Array(Dr).fill(0);


for(int i = 1; i <= Dr; i++){
    x[i] = i;
}
for(int j = 1; j <= Dr; j++){
    Variant z = duniform(1,x.length,RS);
    y[j] = x[z];
    x.splice(z,1);
}


for(int k = 1; k <= y.length; k++){
    Boom_Sequence.addRow(k + 1, 0);
    Boom_Sequence.setRowHeader(k + 1, "" + numtostring(k));
    Boom_Sequence[k + 1][3] = y[k];
}




FlexSim 22.0.16
global tableonresetdeleteallrows
1690406762707.png (81.8 KiB)
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Jason Lightfoot avatar image
1 Like"
Jason Lightfoot answered Jason Lightfoot commented

Note You can refer to the table as current throughout your code.

What do you want it to look like at reset? If you set the size to the number of rows and columns at reset then you've done nothing.

If you want to delete the columns to the right then you can use

current.setSize(current.numRows,2);

But your code isn't adding columns...

Note also that if you set up a model definition table like this:

1690415159485.png

The you can update all the model numbers in one line of sql:

Table.query("UPDATE BoomSequence_3 a, Models b SET a.ModelNumber=b.ModelNumber WHERE a.Model=b.Model");

1690415159485.png (5.2 KiB)
· 4
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Luis Gaytan avatar image Luis Gaytan commented ·

Thanks, @Jason Lightfoot for the answer, I want the table look like this:

1690903489738.png

when I write:

current.setSize(current.numRows,2);

It deletes the "Order" and "RS" Columns, so I just want to know why the code suppress the info in "Model" and "ModelNumber" Columns, greetings!

0 Likes 0 ·
1690903489738.png (83.1 KiB)
Jason Lightfoot avatar image Jason Lightfoot ♦♦ Luis Gaytan commented ·
Then leave it as it is and don't change the size.
1 Like 1 ·
Luis Gaytan avatar image Luis Gaytan Jason Lightfoot ♦♦ commented ·

so if I want to lookup the order column in another table, how does table.query works?

Im trying something like this, but it doesnt works:

Table.query("UPDATE BoomSequence_2 a, BoomSequence_Order b SET a.Dr=b.Order WHERE a.Order=b.Order");

1690907365151.png

1690907402378.png

0 Likes 0 ·
1690907365151.png (58.5 KiB)
1690907402378.png (87.0 KiB)
Show more comments