question

Stan Davis avatar image
1 Like"
Stan Davis asked Matthew Gillespie commented

Is there a way to do a Global Table Lookup using row and column names and without using query()?

For example, if there is a global table with a single row called "trucks" and two columns "Ford" and "Chevy", can a global table lookup be performed where row = 'trucks' and column = "Chevy" instead of row = 1 and column = 2?? It appears I could use the query() command, but that may require restructuring the table that is being provided as input. Thanks.

FlexSim 16.2.0
global tabledela
· 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.

Matthew Gillespie avatar image Matthew Gillespie ♦♦ commented ·

As of 17.0, with the new Table FlexScript class, you can use row and column names instead of numbers:

Table table = reftable("Data");
int value = table["Trucks"]["Chevy"];
2 Likes 2 ·
Kari Payton avatar image
3 Likes"
Kari Payton answered Stan Davis commented

Hello Stan,

I'm not sure if this addresses your needs, but one way you can reference the columns and rows in a global table is by creating global macros. Toolbox -> Add -> Modeling Logic -> Global Macros

So for your macros you could define a name to reference a number. Input this into the space under the 'Global Macros' tab.

//Table Rows
#define R_Trucks 1

//Table Columns
#define C_Ford 1
#define C_Chevy 2

So, whenever you want to reference that specific column and row in the table use the command line:

gettablenum('table name', R_Trucks, C_Chevy)

If the macros are entered correctly, the text will turn a light blue color in the gettablenum() command.

· 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.

Stan Davis avatar image Stan Davis commented ·

Thanks Kari

1 Like 1 ·
Cameron Pluim avatar image
2 Likes"
Cameron Pluim answered Stan Davis commented

@Stan Davis, one option you have is to use Global Macros. You can set them up to look like this:

and then in your code you could use those names that you define in your global macros page like so:

gettablenum("MyTable",TRUCKS_ROW,CHEVY_COL)

This way you don't need to remember which row is your trucks row, or which column is Chevy, but if you do change the order in the table, you will need to go in and manually change the global macro to reference the correct row/column number.


globalmacros.jpg (46.2 KiB)
· 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.

Stan Davis avatar image Stan Davis commented ·

Thanks Cameron

0 Likes 0 ·

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.