Problem with MinFunction

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

  • Posted 8 September 2017, 12:50 pm EST

    Hello,<br><br>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.<br><br>The AVG and StdDev work fine, but the MIN or MAX causes the program to crash.  <br><br>object[] v = new object[rc];<br>foreach (DataRow RowIn in dt.Select())<br>    v.SetValue(System.Convert.ToSingle(RowIn["AvgOfTotal_Time"]),current_row);<br><br> float Mean = System.Convert.ToSingle(FarPoint.CalcEngine.AverageFunctionInfo.AverageFunction.Evaluate(v));<br> float StdDev = System.Convert.ToSingle(FarPoint.CalcEngine.StDevFunctionInfo.StDevFunction.Evaluate(v));<br>float M1 = System.Convert.ToSingle(FarPoint.CalcEngine.MinFunctionInfo.MinFunction.Evaluate(v));<br> float M2 = System.Convert.ToSingle(FarPoint.CalcEngine.MaxFunctionInfo.MaxFunction.Evaluate(v));<br><br>What am I doing wrong?<br><br>Thanks,<br><br>Martin Haas<br><br>
  • Replied 8 September 2017, 12:50 pm EST

    <P>I tested similar code which worked fine for me...</P>
    <P>    object[] v = new object[] {10.0f, 7.0f, 9.0f, 27.0f, 2.0f};<BR>    float Mean = System.Convert.ToSingle(FarPoint.CalcEngine.AverageFunctionInfo.AverageFunction.Evaluate(v));<BR>    float StdDev = System.Convert.ToSingle(FarPoint.CalcEngine.StDevFunctionInfo.StDevFunction.Evaluate(v));<BR>    float M1 = System.Convert.ToSingle(FarPoint.CalcEngine.MinFunctionInfo.MinFunction.Evaluate(v));<BR>    float M2 = System.Convert.ToSingle(FarPoint.CalcEngine.MaxFunctionInfo.MaxFunction.Evaluate(v));</P>
    <P>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.</P>
Need extra support?

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

Learn More

Forum Channels