ValidationElement: Integer;
The ValidationElement property returns the element index in validations dimension that corresponds to formula.
If a point is calculated by a formula from control block, value in this point can be obtained from validations matrix. To get value, create a coordinate that corresponds with the source point and also has the additional validations dimension. The ValidationElement property returns the element index in validations dimension. Validations dimension elements are created on executing control block.
Executing the example requires that the repository contains a calculation algorithm with the CALG_ALG identifier. The algorithm uses control block.
Add links to the Cubes, Dimensions, Matrix, Metabase, Ms system assemblies.
Sub UserProc;
Var
Mb: IMetabase;
MDesc, MDescChild: IMetabaseObjectDescriptor;
Problem: IMsProblem;
Calc: IMsProblemCalculation;
CalcSet: IMsProblemCalculationSettings;
Variable: IVariableStub;
SelFactory: DimSelectionSetFactory;
SelSet, ValSelSet: IDimSelectionSet;
Sel: IDimSelection;
Res: IMsFormulaInfoList;
ResI: IMsFormulaInfo;
Point: IMsFormulaGenTermPoint;
DimInst: IDimInstance;
ValidMatrix: IMatrix;
NewCoord: IMatrixCoord;
s: string;
k, i, El: integer;
Begin
Mb := MetabaseClass.Active;
// Calculation algorithm
MDesc := Mb.ItemById("CALC_ALG");
// Get modeling container
For Each MDescChild In MDesc.Children Do
If MDescChild.ClassId = MetabaseObjectClass.KE_CLASS_MODELSPACE Then
MDesc := MDescChild;
Break;
End If;
End For;
// Get problem
For Each MDescChild In MDesc.Children Do
If MDescChild.ClassId = MetabaseObjectClass.KE_CLASS_MSPROBLEM Then
Break;
End If;
End For;
Debug.WriteLine(MDescChild.Key.ToString + " " + MDescChild.Id + " " + MDescChild.Name);
// Calculate problem
Problem := MDescChild.Edit As IMsProblem;
CalcSet := Problem.CreateCalculationSettings;
CalcSet.SupportPartialCalculation := True;
Calc := Problem.Calculate(CalcSet);
Calc.Run;
// Get data source, for which calculation is executed
Variable := Calc.VariableStubs.Item(0);
// Create selection. First dimension elements are selected
SelFactory := New DimSelectionSetFactory.Create;
SelSet := SelFactory.CreateDimSelectionSet;
Sel := SelSet.Add((Variable.Calendar As IMetabaseObject).Open(Null) As IDimInstance);
Sel.SelectElement(0, False);
k := Variable.DimensionCount;
For i := 0 To k - 1 Do
Sel := SelSet.Add((Variable.Dimension(i) As IMetabaseObject).Open(Null) As IDimInstance);
Sel.SelectElement(0, False);
End For;
// Get formula information
Res := Calc.GetFormulaInfo(Variable.Key, SelSet);
If (Res.Count = 0) Then
Debug.WriteLine("Point is not calculated");
Else
Debug.WriteLine("Total number of models, by which point is calculated: " + Res.Count.ToString);
For i := 0 To Res.Count - 1 Do
ResI := Res.Item(i);
Debug.WriteLine("=========== " + (i + 1).ToString + " ===========");
Debug.WriteLine("Model: " + ResI.Model.Name);
Debug.WriteLine("Metamodel: " + ResI.MetaModel.Name);
Debug.WriteLine("Problem: " + ResI.Problem.Name);
Debug.WriteLine("Formula expression: " + ResI.Expression);
// Information about calculation point
Point := ResI.InstancesIterator.LeftPart.Point;
SelSet := (Point.Coord(0).MatrixModel As IMatrix).Dimensions;
For k := 0 To SelSet.Count - 1 Do
DimInst := SelSet.Item(k).Dimension;
s := s + DimInst.Name + " = " + DimInst.Elements.Name(Point.Coord(0).Item(k)) + " ";
End For;
Debug.WriteLine("Calculation point: " + s);
// Get element in validations dimension
</font><font color="#000000"> El := ResI.ValidationElement;<br/> Debug.WriteLine(</font><font color="#800000">"ValidationElement : "</font><font color="#000000"> + El.ToString);<br/> </font><font color="#008080">If</font><font color="#000000"> El <> -</font><font color="#008000">1</font><font color="#000000"> </font><font color="#008080">Then</font><font color="#000000"><br/> </font><font color="#008000">// If there is element, get validations matrix<br/> </font><font color="#000000"> ValidMatrix := Calc.GetValidationExceptions(Variable.Key).Execute(</font><font color="#008080">Null</font><font color="#000000">);<br/> </font><font color="#008000">// Create a coordinate to get value from validations matrix<br/> </font><font color="#000000"> ValSelSet := ValidMatrix.Dimensions;<br/> NewCoord := ValidMatrix.CreateCoord;<br/> </font><font color="#008080">For</font><font color="#000000"> k := </font><font color="#008000">0</font><font color="#000000"> </font><font color="#008080">To</font><font color="#000000"> ValSelSet.Count - </font><font color="#008000">1</font><font color="#000000"> </font><font color="#008080">Do</font><font color="#000000"><br/> Sel := SelSet.FindByKey(ValSelSet.Item(k).Dimension.Key);<br/> </font><font color="#008080">If</font><font color="#000000"> Sel <> </font><font color="#008080">Null</font><font color="#000000"> </font><font color="#008080">Then</font><font color="#000000"><br/> </font><font color="#008000">// If dimension is regular, put element from selection to coordinate<br/> </font><font color="#000000"> NewCoord.Item(k) := Sel.FirstDimElement;<br/> </font><font color="#008080">Else</font><font color="#000000"><br/> </font><font color="#008000">// If dimension is validations dimension, put the obtained element to coordinate<br/> </font><font color="#000000"> NewCoord.Item(k) := El;<br/> </font><font color="#008080">End</font><font color="#000000"> </font><font color="#008080">If</font><font color="#000000">;<br/> </font><font color="#008080">End</font><font color="#000000"> </font><font color="#008080">For</font><font color="#000000">;<br/> </font><font color="#008000">// Get value from validations matrix<br/> </font><font color="#000000"> Debug.WriteLine(</font><font color="#800000">"Value: "</font><font color="#000000"> + ValidMatrix.Item(NewCoord));<br/> </font><font color="#008080">Else</font><font color="#000000"><br/> Debug.WriteLine(</font><font color="#800000">"Value: "</font><font color="#000000"> + Point.Value(</font><font color="#008000">0</font><font color="#000000">));<br/> </font><font color="#008080">End</font><font color="#000000"> </font><font color="#008080">If</font><font color="#000000">;<br/> </font><font color="#008080">End</font><font color="#000000"> </font><font color="#008080">For</font><font color="#000000">;<br/> </font><font color="#008080">End</font><font color="#000000"> </font><font color="#008080">If</font><font color="#000000">;<br/> </font><font color="#008080">End</font><font color="#000000"> </font><font color="#008080">Sub</font><font color="#000000"> UserProc;</font>
After executing the example, the modeling problem used by control block is calculated. The development environment console displays information about the formulas used on calculation in the first model calculation point. The point value is obtained from validations matrix.
See also: