Add(Variable: IMsVariable): Boolean;
Variable. A modeling variable that must be added to the collections.
The Add method adds a modeling variable to the collection and returns True if the adding was successful.
NOTE. The variables adding specifics depends on the area where its applied.
The given example sets up the model for the calculation using the linear regression method.
Sub Main;
Var
MB: IMetabase;
MObj: IMetabaseObject;
Model: IMsModel;
Variable: IMsVariable;
Trans: IMsFormulaTransform;
VarTrans: IMsFormulaTransformVariable;
Tree: IMsFormulaTransformSlicesTree;
Slice: IMsFormulaTransformSlice;
Selector: IMsFormulaTransformSelector;
Formula: IMsFormula;
Linear: IMsLinearRegressionTransform;
Begin
MB := MetabaseClass.Active;
MObj := MB.ItemByIdNamespace("MODEL_1", MB.ItemById("KONT_MODEL").Key).Edit;
Variable := MB.ItemByIdNamespace("Var_1", MB.ItemById("KONT_MODEL").Key).Bind As IMsVariable;
Model := MObj As IMsModel;
Trans := Model.Transform;
// add output variable
Model.Output.Add(Variable);
VarTrans := Trans.Outputs.FindById("VAR_1");
Tree := VarTrans.SlicesTree(VarTrans);
Slice := Tree.CreateSlice(1);
Selector := Model.Transform.CreateSelector;
Selector.Slice := Slice;
Formula := Model.Transform.Transform(Selector);
Formula.Kind := MsFormulaKind.LinearRegression;
Linear := Formula.Method As IMsLinearRegressionTransform;
//add input variable
Variable := MB.ItemByIdNamespace("Var_Factor", MB.ItemById("KONT_MODEL").Key).Bind As IMsVariable;
Model.Input.Add(Variable);
Slice := Trans.Inputs.FindById("VAR_FACTOR").Slices.Add(Null);
Linear.Explanatories.Add.Expression.AsString := Trans.SliceToTerm(Slice, "");
MObj.Save;
End Sub Main;
After executing the example a variable with the VAR_1 identifier is added to the model with the MODEL_1 identifier as an output variable, and a variable with the VAR_FACTOR identifier is added as the input variables (factors).
See also: