How to reference values in an array in a table cell

How to reference values in an array in a table cell

patrickABAWF
Collaborator Collaborator
28 Views
6 Replies
Message 1 of 7

How to reference values in an array in a table cell

patrickABAWF
Collaborator
Collaborator

[ FlexSim 20.0.2 ]

I have global tables for which the cell format is array so that I can put many values in each cell.

What is the correct syntax to reference a specific value in an array in a cell?

For exemple, I reference the cell with Table("Interventions")[5] but that gives me the whole cell content. I just want to reference one value in the array in the cell.

By default all arrays in every cell have the same name: Array[1]

Thanks,

0 Likes
Accepted solutions (1)
29 Views
6 Replies
Replies (6)
Message 2 of 7

Matthew_Gillespie
Autodesk
Autodesk
Accepted solution

Here are a few ways you could do it:

return Table("Interventions")[5].as(Array)[2];
Array array = Table("Interventions")[5];
return array[2];
return Table("Interventions").cell(i, 5).value[2];


Matthew Gillespie
FlexSim Software Developer

0 Likes
Message 3 of 7

patrickABAWF
Collaborator
Collaborator

When I write this (with an index of 1) it returns the whole array.

If I put an index greater than 1, I get "Array index out of bounds".

And all my arrays have a length of at least 3.

0 Likes
Message 4 of 7

Matthew_Gillespie
Autodesk
Autodesk

Do you have an array of length 3 inside another array of length 1?

You said "By default all arrays in every cell have the same name: Array[1]". That looks like you only have length 1 arrays in the table.

Maybe you should attach the model?



Matthew Gillespie
FlexSim Software Developer

0 Likes
Message 5 of 7

Jacob_Gillespie
Autodesk
Autodesk

Maybe you are mistaken in how you think the array is set up?

It sounds like you have an array inside an array.

0 Likes
Message 6 of 7

patrickABAWF
Collaborator
Collaborator

All methods return the same problem. Might be the way the array is setup in the table.arrays.fsm

Here is my simplified model. The code is in the "Find room" box.

0 Likes
Message 7 of 7

Matthew_Gillespie
Autodesk
Autodesk

All the arrays in this model are length 1. They have a single string inside of them. For example, cell 1,5 has the string

3,4,5,6,7

You need to double click on the arrays so that it opens a new table editor and then add 5 rows and put a different number in each row. Then the table will look like this:

Array[5]: {3, 4, 5, 6, 7}

instead of this:

Array[1]: {3,4,5,6,7}

Or just use code to set the cells:

Table("Interventions")[1][5] = [3,4,5,6,7];


Matthew Gillespie
FlexSim Software Developer

0 Likes