你好,
我的脚本有问题。
当我尝试使用循环时,我得到一个空列。
当我不使用循环时,它是有效的。
col = dt << get column names;
For(i = 1, i <= N Items(col), i++,
c = "c" || Char(i);
Eval(Parse(Eval Insert("^c^= column(dt,i)<<GET values=""></GET>New Column( "Flag",<BR /> Character,<BR /> Nominal,<BR /> Formula(for(i=1,i<3,i++,<BR /> if(c2[i]>:LSL[i],"Pass","Failed"))));<BR />
我要说的第一件事是,这是一个XY问题. 但是要回答如何使标志检查动态列数的问题,我会在公式本身之外构建公式。
names default to here(1);
dt = New Table( "Test",
Add Rows( 5 ),
Set Header Height( 46 ),
New Column( "System",
Character,
"Nominal",
Set Values( {"F_T_F_S", "F_T_F_R", "F_T_F_T", "F_T_F_U", "F_T_F_V"} )
),
New Column( "01/09/2019",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [500, 450, 900, 358, 500] )
),
New Column( "01/10/2019",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [666, 120, 280, 852, 456] )
),
New Column( "01/11/2019",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [520, 500, 450, 520, 520] )
),
New Column( "01/12/2019",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [450, 666, 120, 450, 450] )
),
New Column( "LSL",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [500, 800, 800, 0, 0] )
),
New Column( "USL",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [980, 1100, 1100, 3700, 3700] )
)
);
//build the formula outside of the formula itself
ANDExpr = Expr(AND()); // we're going to throw all relavent columns into this AND Expression
for(i=2, i<=5, i++,
col = Column(i);
insert into(ANDExpr,
EvalExpr(:LSL < Expr(col)[] < :USL) // for each column check that it's between LSL & USL
);
);
f = EvalExpr(
if(Expr(nameexpr(ANDExpr)),
"Pass",
"Fail"
)
);
show(nameexpr(f));
Eval(EvalExpr(dt << New Column("Flag", formula(Expr(nameexpr(f)))) ));
你也可以做一个名字列表而不是数字。
谢谢你的回答。
* 根据你的脚本,它运行得不太好——我每一行都得到相同的答案,因为你在循环之后打印。
*至于大问题-
你打算做什么?
我需要检查 LSL 和 USL 之间的每一行(到所有列)——但问题是,列的名称一直在变化。

我怀疑您的通过/失败未作为最后计算值返回。以下调整可能会解决您的问题。
col = dt << get column names;
For( i = 1, i <= N Items( col ), i++,
c = "c" || Char( i );
Eval( Parse( Eval Insert( "^c^= column(dt,i)<<GET values=""> :LSL[i],
x = "Pass",
x = "Failed"
)
);
x;
)
);</GET>
但是,你有一个更大的问题。 您的公式依赖于一个名为“c2”的内存变量才能工作。如果您更改或删除该变量的值,公式将使用更改后的值来计算公式,或者如果它已被删除,则公式将不再有效。