question

ABarranco avatar image
0 Likes"
ABarranco asked ABarranco commented

Trouble adding columns and rows to in-memory tables in FlexScript

I’m trying to use in-memory tables in FlexScript to perform some calculations. However, I’m having trouble adding columns and rows to the tables. I don’t want to create Global Tables.

Here’s the script I’ve tried, but the return value is zero:

Table testTable;
testTable.setSize(4,4, DATATYPE_NUMBER);
return(testTable.numCols);

Can anyone help me figure out what I’m doing wrong?

Mensaje recibido. Sure! Here's a revised version of your text: I'm trying to use in-memory tables in FlexScript to perform some calculations. However, I'm having trouble adding columns and rows to the tables. I don't want to create Global Tables. Here's the script I've tried, but the return value is zero: ``` Table testTable; testTable.setSize(4,4, DATATYPE_NUMBER); return(testTable.numCols); ``` Can anyone help me figure out what I'm doing wrong?

FlexSim 23.1.1
flexscripttables
· 3
5 |100000

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

Joerg Vogel avatar image Joerg Vogel commented ·
Maybe you need another table operation, like adding values to cells.
0 Likes 0 ·
ABarranco avatar image ABarranco Joerg Vogel commented ·

Thank you for your suggestion. I tried adding values to cells, but I got an exception error: “FlexScript exception: Invalid row number: 1 in <no path> at <no path> c: <no path> i: <no path>”.

0 Likes 0 ·
ABarranco avatar image ABarranco commented ·

I found a solution that works, but it seems a bit unconventional. Here’s the script I used:

Array testArray;
Table testTable = testArray.as(Table);
testTable.addRow();
testTable.addCol();
return testTable.numCols;

Is there a more standard way to achieve the same result?

0 Likes 0 ·

1 Answer

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

The array approach is probably as good as any but be aware that some functions that have a table passed to them (eg. dempirical) will require a node containing the table data. In those cases you can create a temporary node and destroy it afterwards (I often create a user command called 'createtempnode' which places nodes in a new folder at 'Tools/temp' and returns a pointer to the node).

· 1
5 |100000

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

ABarranco avatar image ABarranco commented ·

Thank you @Jason Lightfoot! I will keep your suggestion about the nodes in mind and follow your same strategy.

0 Likes 0 ·