Hallo Leute,
Ich versuche, bei jedem Aufruf der Funktion einen neuen Wert (Variablenwert) zu einer Liste innerhalb einer Funktion hinzuzufügen.
Egal, was ich versucht habe, die Liste erhält keinen Wert.
Irgendwelche Ratschläge?
Hinzufügen des Beispielcodes
Ich denke, es ist eine bessere Idee, die neue Spalte zurückzugeben und diese dann außerhalb des Funktionsaufrufs hinzuzufügen
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));
Vollständiges Beispiel
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")};
Und wenn Sie wirklich in die außerhalb der Funktion erstellte Liste einfügen möchten, entfernen Sie {Default Local} aus Ihrer Funktion (es gibt auch andere Methoden), aber das würde ich nicht empfehlen. Ein Grund dafür ist, dass Sie jetzt immer op_list erstellen müssen, bevor die Funktion aufgerufen wird.
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")};