View Variable Values

This section describes the procedure of displaying variable values in the console window.

In the modeling example, after problem calculation results were loaded to the Balance of Trade, billion USD variable by the Fact scenario. The unit described below is used to view these results.

Add links to the Cubes, Dimensions, Matrix, Metabase, and Ms system assemblies.

Sub UserProc;
Var
    MB: IMetabase;
    KMDesc: IMetabaseObjectDescriptor;
    Problem: IMsProblem;
    VarList: IVariableStubList;
    VarStub: IVariableStub;
    VarObj: IMetabaseObject;
    CubeInst: ICubeInstance;
    Des: ICubeInstanceDestination;
    DimSS: IDimSelectionSet;
    DimS: IDimSelection;
    Elem: IDimElementArray;
    Mat: IMatrix;
    Coord: IMatrixCoord;
    i: Integer;
Begin
    MB := MetabaseClass.Active;
    KMDesc := MB.ItemById("MODEL_SPACE");
    Problem := mb.ItemByIdNamespace("PROBLEM_BALANCE", KMDesc.Key).Bind As IMsProblem;
    // Get output variable
    VarList := Problem.VariableStubs(MsVariableKind.Output);
    VarStub := VarList.FindById("BALANCE");
    // Get variable view in express analysis
    VarObj := (VarStub As IMsVariable).Cube As IMetabaseObject;
    CubeInst := VarObj.Open(NullAs ICubeInstance;
    Des := CubeInst.Destinations.DefaultDestination;
    DimSS := Des.CreateDimSelectionSet;
    // Select frequency, for which data will be displayed: Years
    DimS := DimSS.Item(0);
    Elem := DimS.Dimension.Levels.Item(0).Elements;
    For Each i In Elem Do
        DimS.SelectElement(i, False);
    End For;
    // Select the Fact scenario dictionary
    DimSS.Item(1).SelectAll;
    // Get variable data matrix
    Mat := Des.Execute(DimSS);
    Coord := Mat.CreateCoord;
    Coord.Item(1) := 0;
    // Display matrix with data in the console window
    Debug.WriteLine("Variable data '" + VarStub.Name + "':");
    For Each i In Elem Do
        Coord.Item(0) := i;
        Mat.Item(Coord) := Math.RandBetween(50100);
        Debug.WriteLine(Mat.Item(Coord));
    End For;
End Sub UserProc;

After executing the example, problem calculation data loaded to the Balance of Trade, billion USD variable is displayed in the console window.

See also:

General Principles of Programming using Ms Assembly