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