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

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

hai_l2
Not applicable
10 Views
7 Replies
Message 1 of 8

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

hai_l2
Not applicable

[ FlexSim 20.1.2 ]

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

Accepted solutions (1)
11 Views
7 Replies
Replies (7)
Message 2 of 8

Matthew_Gillespie
Autodesk
Autodesk
Accepted solution

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;
}


Matthew Gillespie
FlexSim Software Developer

Message 3 of 8

hai_l2
Not applicable

Thank you

0 Likes
Message 4 of 8

hai_l2
Not applicable

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

This that expected?

DATATYPE_COUPLING  3
0 Likes
Message 5 of 8

Matthew_Gillespie
Autodesk
Autodesk

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



Matthew Gillespie
FlexSim Software Developer

0 Likes
Message 6 of 8

hai_l2
Not applicable

I added a sample file.

Note that the global table values were imported from excel.

0 Likes
Message 7 of 8

Matthew_Gillespie
Autodesk
Autodesk

@Hai L2 There are two different sets of type macros: variant types and node datatypes. The table in your model has number data in the first column and string data in the second.

So if you look at the variant type of the cell's values you'll get:

Variant value = Table("GlobalTable1")[1][1];
return value.type;  // VAR_TYPE_NUMBER 1
Variant value = Table("GlobalTable1")[1][2];
return value.type;  // VAR_TYPE_STRING 3

If you look at the datatype of the cell itself you'll get:

treenode cell = Table("GlobalTable1").cell(1,1);
return cell.dataType;  // DATATYPE_NUMBER 1
treenode cell = Table("GlobalTable1").cell(1,2);
return cell.dataType;  // DATATYPE_STRING 2


Matthew Gillespie
FlexSim Software Developer

0 Likes
Message 8 of 8

hai_l2
Not applicable

Matt, the info you provided allows me to do what I needed. Thanks!!!

0 Likes