question

sara S2 avatar image
0 Likes"
sara S2 asked sara S2 commented

How to write a vector in global table ?

Hello,

I want to write a vector in the global table "GlbT" according to "r" values in the "Custom code" of the processflow. This must be like: {1 2 3}. I assigned "array data" in the global table “GlbT” and wrote the "Custom code", but it is not giving {1 2 3}.

Please help me to fix this.

Regards.

hospital1.fsm

FlexSim 19.0.0
global tables
hospital1.fsm (83.4 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.

Regan Blackett avatar image
1 Like"
Regan Blackett answered Regan Blackett commented

@sara S2

On line 19 of your custom code you wrote:

table[1][1] = r;

Which means that the value of 'r' is written to the cell, which doesn't add a value to the array. Instead you would need to write:

table[1][1].as(Array).push(r);

So that your current 'r' value is put into the array; this method also frees you from needing to know which index of the array to place your 'r' value into.

One thing though for this to work properly, when you assign array data to the table cell, double click the cell to bring up the properties, and set the rows to 0. Otherwise your array will read {0, 1, 2, 3} since it assumes an array length of 1 and a value of zero in the array index.

· 6
5 |100000

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

sara S2 avatar image sara S2 commented ·

@Regan Blackett thank you so much for your help.

0 Likes 0 ·
sara S2 avatar image sara S2 commented ·

@Regan Blackett how could I reset the cell to Array[0]{0} when clicking "Reset" button?

0 Likes 0 ·
Braydn T avatar image Braydn T sara S2 commented ·

Add an onReset trigger from the toolbox.

0 Likes 0 ·
Regan Blackett avatar image Regan Blackett ♦ sara S2 commented ·

There's actually an option to do that in the On Reset trigger of the table itself:

0 Likes 0 ·
sara S2 avatar image sara S2 Regan Blackett ♦ commented ·

Okay, but in case I have a global table of several columns & rows and only one column that is of type array data and the other columns are of type number data. How should I reset the column of type array data while I have this reset code (FIG):

fig.png

0 Likes 0 ·
fig.png (140.6 KiB)
Show more comments
sara S2 avatar image
0 Likes"
sara S2 answered sara S2 commented

@Regan Blackett, thank you for your reply.

In fact, only the array column needs to be reset. I tried to write a code to reset it like I did for the columns with number data, for exp:

for (int col = 8; col <= 8; col++) { for (int row = 1; row <= current.numRows; row++){ settablenum("CUDB",row,col,0); } }

Instead of 0 I tried several expressions ([], Array[0]{0}...) related to array data but they were all invalid.

Would you please tell me what is the convenient expression?

for (int col = 8; col <= 8; col++) { for (int row = 1; row <= current.numRows; row++) { settablenum("CUDB",row,col,0); } }

· 5
5 |100000

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

sara S2 avatar image sara S2 commented ·

@Matthew Gillespie would you please help me to fix this ?

0 Likes 0 ·
Regan Blackett avatar image Regan Blackett ♦ commented ·

In the code for the On Reset trigger you would find this expression:

if (cell.value.is(Array)) {
                   
cell.value = [ ];
}

Therefore to make an empty array set the value to the empty set of square brackets:

Table("CUDB", row, col) = [];
0 Likes 0 ·
sara S2 avatar image sara S2 Regan Blackett ♦ commented ·

@Regan Blackett, Thank you for the reply. But really I didn't understand your answer!

0 Likes 0 ·
Regan Blackett avatar image Regan Blackett ♦ sara S2 commented ·

@sara S2

I'm sorry I realize now I incorrectly the typed the expression.

Table("CUDB")[row][col] = [ ];

The above sets the table cell indicated by the row and col variables to an empty array. You can use that in the example for() loop you posted in place of settablenum(), don't use settablenum().

1 Like 1 ·
Show more comments

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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