嘿夥計們,
我試圖在每次調用函數時將新值(變數值)添加到函數內的列表中。
無論我嘗試什麼,該清單都沒有任何價值。
有什麼建議嗎?
新增程式碼範例
我認為最好返回新列,然後將其添加到函數呼叫之外
Names Default To Here(1);
dt = Open("\\VMSPFSFSLC001\F28_PLI\SQL\FE SQL\Data\Oxide .CSV");
op_list = List();
add_new_operation = Function({dt, col_name, op, PLmin, PLmax}, {Default Local},
new_col = dt << New Column(col_name,
Character,
"Nominal",
Formula(
If(/*some conditions for the value*/
)
)
);
return(new_col);
);
sticol = add_new_operation(dt, "STI", 201405, 80, 2000);
Insert Into(op_list, sticol);
Show(op_list);
// This should also work
// Insert into(op_list, add_new_operation(dt, "STI", 201405, 80, 2000));
完整範例
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
op_list = {};
add_new_operation = Function({dt, col_name}, {Default Local},
new_col = dt << New Column(col_name,
Character,
"Nominal",
Formula(
col_name
)
);
return(new_col);
);
Show(op_list); // op_list = {};
Insert into(op_list, add_new_operation(dt, "name"));
Insert into(op_list, add_new_operation(dt, "age"));
Show(op_list); // op_list = {Column("name 2"), Column("age 2")};
如果您確實想插入到在函數外部建立的清單中,請從函數中刪除 {Default Local} (還有其他方法),但我不建議這樣做。原因之一是現在必須在呼叫函數之前始終建立 op_list。
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
op_list = {};
add_new_operation = Function({dt, col_name},
new_col = dt << New Column(col_name,
Character,
"Nominal",
Formula(
col_name
)
);
Insert Into(op_list, new_col);
);
Show(op_list); // op_list = {};
add_new_operation(dt, "name");
add_new_operation(dt, "age");
Show(op_list); // op_list = {Column("name 2"), Column("age 2")};