Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Excerpt

Calculates a custom function returning a FunctionValue given a list of ComputationResult FunctionValue arguments and the function's current Cell for context.

Signature
C#
C#
ComputationResultFunctionValue CustomFunctionCalculate(IList<ComputationResult>IList<FunctionValue> args, Cell currentCell)
Signature
vb.net
vb.net
Function CustomFunctionCalculate(IList<ComputationResult> args, Cell currentCellargs As IList(Of FunctionValue), currentCell As Cell) As ComputationResultFunctionValue

Parameters

Param
0args

An ordered list of FunctionValue arguments that have already been fully evaluated.

Param
0currentCell

The Cell that the current function resides in to use for context sensitive operations

Returns

A ComputationResult FunctionValue that contains the resulting value of the function.

 

 

Example
Code Block
csharp
csharp
titleC#
        public ComputationResultFunctionValue CustomFunctionCalculate(IList<ComputationResult>IList<FunctionValue> args, Cell currentCell)
        {
            StringBuilder result = new StringBuilder("");
             foreach (ComputationResultFunctionValue arg in args)
            if ({
                result.Append(',');
                switch (arg.Type)
!= ComputationResultType.RANGE)
                   {
                    case FunctionValueType.BOOLEAN:
                        result.Append((bool)arg.Value ? "True" : "False");
                        break;
                    case FunctionValueType.STRING:
                        result.Append(arg.Value);
                        break;
                    case FunctionValueType.NUMBER:
                        result.Append(((double)arg.Value).ToString("0.#####"));
                        break;
                    case FunctionValueType.NULL:
                        result.Append(' ');
                        break;
                    case FunctionValueType.RANGE:
                        result.Append(arg.Value.ToString());
                        break;
                }
            }
            return new ComputationResultFunctionValue(result.ToString());
        }
Code Block
vb.net
vb.net
titlevb.net
    Public Function CustomFunctionCalculate(args As IList(Of ComputationResultFunctionValue), currentCell As Cell) As ComputationResultFunctionValue
        Dim result As New StringBuilder("")
         
        For Each arg As ComputationResultFunctionValue In args
            If result.Append(",")
 
            Select Case arg.Type
<> ComputationResultType.RANGE Then                Case FunctionValueType.[BOOLEAN]
                    result.Append(If(CBool(arg.Value), "True", "False"))
                    Exit Select
                Case FunctionValueType.[STRING]
                    result.Append(arg.Value)
                    Exit Select
                Case FunctionValueType.NUMBER
                    result.Append(CDbl(arg.Value).ToString("0.#####"))
                    Exit Select
                Case FunctionValueType.NULL
                    result.Append(" ")
                    Exit Select
                Case FunctionValueType.RANGE
                    result.Append(arg.Value.ToString())
                    Exit Select
            End IfSelect
        Next
        Return New ComputationResultFunctionValue(result.ToString())
    End Function