for循環中的問題大家好,我無法弄清楚為什麼這個 for 循環公式不起作用。 如果單位是及時的,它只是創建一個新列,然後將其轉換為小時。 樣本數據也附上。 謝謝。
ColNames = dt << get column names( string, Numeric, character, continuous, Nominal );
N Items( ColNames );
For( i = 1, i <= N Items( ColNames ), i++,
If( Ends With( ColNames[i], "(secs)" ),
New Column (Concat(ColNames[i], "_to_", "Hr"), Formula(AS Column(ColNames[i])/3600) ),
Ends With( ColNames[i], "(min)" ),
New Column (Concat(ColNames[i], "_to_", "Hr"), Formula(AS Column(ColNames[i])/60) ),)
);
Wait( 0 );
腳本回复:for循環中的問題問題是公式元素不解析呈現的公式,然後將生成的代碼放入公式中。因此,呈現給公式元素的內容必須正是公式所需的 JSL。下面是你的jsl的返工
Names Default To Here( 1 );
dt = Current Data Table();
ColNames = dt << get column names( string, Numeric, character, continuous, Nominal );
//N Items( ColNames );
For( i = 1, i <= N Items( ColNames ), i++,
If(
Ends With( ColNames[i], "(secs)" ),
New Column( Concat( ColNames[i], "_to_", "Hr" ),
Formula( Eval( Parse( ":\!"" || ColNames[i] || "\!"n / 3600" ) ) )
),
Ends With( ColNames[i], "(min)" ),
New Column( Concat( ColNames[i], "_to_", "Hr" ),
Formula( Eval( Parse( ":\!"" || ColNames[i] || "\!"n / 60" ) ) )
),
)
);回复:for循環中的問題您也可以考慮使用JSL 報價() ,這允許代碼保持突出顯示
Names Default to Here( 1 );
dt = Current Data Table();
For( i = 1, i <= N Cols( dt ), i++,
column name = Column( dt, i ) << Get Name;
If( Ends With( column name, "(secs)" ),
Eval( Parse( Eval Insert( JSL Quote(
dt << New Column( "^column name^_to_Hr", Formula( :Name("^column name^" ) / 3600 ) )
) ) ) )
,
Ends With( column name, "(min)" ),
Eval( Parse( Eval Insert( JSL Quote(
dt << New Column( "^column name^_to_Hr", Formula( :Name("^column name^" ) / 60 ) )
) ) ) )
)
);