Problem with MinFunction

Posted by: martin_haas on 8 September 2017, 12:50 pm EST

  • Posted 8 September 2017, 12:50 pm EST

    Hello,

    I am using version 3.  I have an array of values that I am trying to use the Calcengine to evaluate the AVG, StdDev, MIN, MAX.

    The AVG and StdDev work fine, but the MIN or MAX causes the program to crash. 

    object[] v = new object[rc];
    foreach (DataRow RowIn in dt.Select())
        v.SetValue(System.Convert.ToSingle(RowIn["AvgOfTotal_Time"]),current_row);

     float Mean = System.Convert.ToSingle(FarPoint.CalcEngine.AverageFunctionInfo.AverageFunction.Evaluate(v));
     float StdDev = System.Convert.ToSingle(FarPoint.CalcEngine.StDevFunctionInfo.StDevFunction.Evaluate(v));
    float M1 = System.Convert.ToSingle(FarPoint.CalcEngine.MinFunctionInfo.MinFunction.Evaluate(v));
     float M2 = System.Convert.ToSingle(FarPoint.CalcEngine.MaxFunctionInfo.MaxFunction.Evaluate(v));

    What am I doing wrong?

    Thanks,

    Martin Haas

  • Replied 8 September 2017, 12:50 pm EST

    Martin,


    I tested similar code which worked fine for me...


        object[] v = new object[] {10.0f, 7.0f, 9.0f, 27.0f, 2.0f};
        float Mean = System.Convert.ToSingle(FarPoint.CalcEngine.AverageFunctionInfo.AverageFunction.Evaluate(v));
        float StdDev = System.Convert.ToSingle(FarPoint.CalcEngine.StDevFunctionInfo.StDevFunction.Evaluate(v));
        float M1 = System.Convert.ToSingle(FarPoint.CalcEngine.MinFunctionInfo.MinFunction.Evaluate(v));
        float M2 = System.Convert.ToSingle(FarPoint.CalcEngine.MaxFunctionInfo.MaxFunction.Evaluate(v));


    What values are you passing into the functions?  What exception occured for you?  Did the exception occur inside the MinFunctionInfo's Evaluate method or did the exception occur when converting the MinFunctionInfo's Evaluate's return value to a single?  The Evaluate method returns an object.  If successful, it would return a boxed double.  Otherwise, it would return a CalcError object.  Attempting to convert a CalcError object to a single would produce an InvalidCastException.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels