Page tree
    Created with Raphaël 2.1.0
    Loading...
Skip to end of metadata
Go to start of metadata

Description

Calculates a custom function returning a FunctionValue given a list of FunctionValue arguments and the function's current Cell for context.
C#
FunctionValue Calculate(IList<FunctionValue> args, Cell currentCell)
vb.net
Function Calculate(args As IList(Of FunctionValue), currentCell As Cell) As FunctionValue

Parameters

args
An ordered list of FunctionValue arguments that have already been fully evaluated.
currentCell
The Cell that the current function resides in to use for context sensitive operations

Returns

A FunctionValue that contains the resulting value of the function.

Examples

C#
public FunctionValue Calculate(IList<FunctionValue> args, Cell currentCell)
{
    StringBuilder result = new StringBuilder("");
    foreach (FunctionValue arg in args)
    {
        result.Append(',');
        switch (arg.Type)
        {
            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 FunctionValue(result.ToString());
}
vb.net
Public Function Calculate(args As IList(Of FunctionValue), currentCell As Cell) As FunctionValue
    Dim result As New StringBuilder("")
      
    For Each arg As FunctionValue In args
        result.Append(",")
 
        Select Case arg.Type
            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 Select
    Next
    Return New FunctionValue(result.ToString())
End Function
  • No labels