Spread 8.0 Documentation
Example
Support Options

Glossary Item Box

Example


The following example implements a "cube(x)" function.

Visual Basic

Private Sub fpSpread1_CustomFunction(ByVal FunctionName As String, ByVal ParameterCnt As Integer, ByVal Col As Long, ByVal Row As Long, Status As Long)
    Dim vResult As Variant
    Dim b As Boolean
    Dim lArg1 As Long
    Dim dfArg1 As Double
    Dim nTypeArg1 As Integer
    Dim nStatusArg1 As Long
    ' Return a status of empty when a result cannot be
    ' computed
    Status = ValueStatusEmpty
    ' Implement the "cube()" custom function
    If FunctionName = "cube" Then
        b = fpSpread1.CFGetParamInfo(1, nTypeArg1, nStatusArg1)
        If nStatusArg1 = ValueStatusOK Then
            If nTypeArg1 = CFGetParamInfoTypeLong Then
                lArg1 = fpSpread1.CFGetLongParam(1)
                vResult = lArg1 * lArg1 * lArg1
                Status = ValueStatusOK
            ElseIf nTypeArg1 = CFGetParamInfoTypeDouble Then
                dfArg1 = fpSpread1.CFGetDoubleParam(1)
                vResult = dfArg1 * dfArg1 * dfArg1
                Status = ValueStatusOK
            End If
        End If
    End If
    If Status = ValueStatusOK Then
        b = fpSpread1.CFSetResult (vResult)
    End If
End Sub

Copyright © GrapeCity, inc. All rights reserved.