我已收到我想讨论的公式大约3年前从@tx尼尔森,从那以后就再也没有放过它,并且之前多次思考过这个问题,慢慢地更加认真地对待脚本编写。 与此同时,公式救了我很多的时间。
在下面的示例中,相同的公式添加了 3 次,每次都有一点变化。 我想讨论的问题是复制和运行表的表脚本(包括新添加的公式列)时抛出的不同错误消息。
Names Default To Here( 1 );
// first, we need an example table
dt = New Table( "ExampleTable",
Add Rows( 24 ),
New Column( "BatchId",
Character,
"Nominal",
Set Values(
{"A", "A", "A", "A", "A", "A", "B", "B", "B", "C", "C", "C", "D", "D",
"D", "E", "E", "E", "F", "F", "F", "G", "G", "G"}
)
),
New Column( "StorageCondition",
Character,
"Nominal",
Set Values(
{"25°C/60%RH", "25°C/60%RH", "25°C/60%RH", "5°C", "5°C", "5°C",
"25°C/60%RH", "25°C/60%RH", "25°C/60%RH", "25°C/60%RH", "25°C/60%RH",
"25°C/60%RH", "25°C/60%RH", "25°C/60%RH", "25°C/60%RH", "25°C/60%RH",
"25°C/60%RH", "25°C/60%RH", "25°C/60%RH", "25°C/60%RH", "25°C/60%RH",
"25°C/60%RH", "25°C/60%RH", "25°C/60%RH"}
)
),
New Column( "Time",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values(
[0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2]
)
),
New Column( "QcParameter",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values(
[0.2, 0.3, 0.4, 0.2, 0.21, 0.22, 0.3, 0.9, 1.2, ., 0.2, 0.4, 0.1, ., 0.1,
0, 0, 0, 0.1, 0, 0, 0, 0.1, 0]
)
)
);
// adding formula column via approach nr. 1<BR />// this adds the formula alright, but when copying and executing the resulting table script will leave the formula column empty<BR />// no need to discuss this, because this obviously missing the 'eval(eval expr(expr()))' wrapping (see screenshot below)
dt << New Column( "QcParameter [% rel.]_1",
numeric,
formula(
curBatch = :BatchId;
curCondition = :StorageCondition;
theRows = dt << get rows where(
:BatchId == curBatch & :StorageCondition == curCondition & :Time == 0
);
d0Row = theRows[1];
d0Time = :QcParameter[d0Row];
(100 * :QcParameter / d0Time);
)
);
// adding formula column via approach nr. 2<BR />// this will fill the formula column as desired when copying and running the table script with the added formula columns<BR />// but it will also throw an error message when new rows are added to the table then (see screenshot below)
Eval(
Eval Expr(
dt << New Column( "QcParameter [% rel.]_2",
numeric,
formula(
curBatch = :BatchId;
curCondition = :StorageCondition;
theRows = Expr( dt ) << get rows where(
:BatchId == curBatch & :StorageCondition == curCondition & :Time == 0
);
d0Row = theRows[1]; // removed from approach nr. 3
d0Time = :QcParameter[d0Row];
(100 * :QcParameter / d0Time);
)
)
)
);
// adding formula column via approach nr. 3
// this will fill the formula column as desired when copying and running the table script with the added formula columns<BR />// and it will NOT throw an error message when new rows are added to the table then (see screenshot below)
Eval(
Eval Expr(
dt << New Column( "QcParameter [% rel.]_3",
numeric,
formula(
curBatch = :BatchId;
curCondition = :StorageCondition;
theRows = Expr( dt ) << get rows where(
:BatchId == curBatch & :StorageCondition == curCondition & :Time == 0
);
d0Time = :QcParameter[theRows];
(100 * :QcParameter) / d0Time;
)
)
)
);
使用其他公式列重新运行表脚本时公式列“QcParameter [%r rel.]_1]”的错误消息的屏幕截图:

重新运行具有附加公式列的表脚本时公式列“QcParameter [%r rel.]_2]”的错误消息的屏幕截图:

重新运行具有附加公式列的表脚本时公式列“QcParameter [%r rel.]_3]”的错误消息的屏幕截图:

我问这个冗长问题的原因是我假设在方法 nr 中使用变量“d0Row”肯定有某种原因。 2、不是吗?对于方法nr。 3 我只是删除了这个变量(见下面的屏幕截图),结果公式的表现“更好”,即,当通过点点击临时添加新行到数据表时,没有错误消息。

因此,我的问题是,我删除“d0Row”变量是否做错了什么。 在现实生活中,我正在使用更大的数据表,并且无法单独检查每一行的准确性。