question

Hai L2 avatar image
1 Like"
Hai L2 asked Joerg Vogel edited

Checking if a cell is blank/null in global table?

Hi,

What is the best way to check if a global table's cell is blank/null?

I've tried the following, but it doesn't seem to work. It always true.

if (table[stepid]["VariableDurationMean"] != NULL)

Thanks,

Hai

Edit: Add test file: TestCellNull.fsm

FlexSim 20.1.2
flexsim 20.1.2table valuecell valuetable cellvariant type
testcellnull.fsm (51.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.

1 Answer

Matthew Gillespie avatar image
1 Like"
Matthew Gillespie answered Hai L2 commented

A table cell can have different types of data assigned to it, and the comparison changes depending on what type the cell is using. This code snippet will do the appropriate comparison based off the type of data assigned to the cell:

Variant value = Table("GlobalTable1")[1][1];
switch(value.type) {
    case VAR_TYPE_NUMBER: return value == 0;
    case VAR_TYPE_STRING: return value == "";
    case VAR_TYPE_ARRAY: return value.length == 0;
    case VAR_TYPE_NODE: return value == nullvar || value == 0;
    case VAR_TYPE_NULL: return 1;
}
· 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.

Hai L2 avatar image Hai L2 commented ·

Thank you

0 Likes 0 ·
Hai L2 avatar image Hai L2 commented ·

For undefined/blank cell value in a global table, I am getting type = 3 instead.

This that expected?

DATATYPE_COUPLING  3
0 Likes 0 ·
Matthew Gillespie avatar image Matthew Gillespie ♦♦ Hai L2 commented ·

Are you getting the datatype of the cell or the type of the variant? Can you post an example of what you're doing?

0 Likes 0 ·
Hai L2 avatar image Hai L2 Matthew Gillespie ♦♦ commented ·

I added a sample file.

Note that the global table values were imported from excel.

0 Likes 0 ·
Show more comments