你好,
我的腳本有問題。
當我嘗試使用循環時,我得到一個空列。
當我不使用循環時,它是有效的。
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”的內存變量才能工作。如果您更改或刪除該變量的值,公式將使用更改後的值來計算公式,或者如果它已被刪除,則公式將不再有效。