ArchView - User functions - example

In definition of view, column User function is Nasob;2
The function multiplies the value by parameter (number two) before displaying.

Private Function Nasob(ArcBId As Long, Id As Long,NumItems As Long, UserParams As Variant) As Variant
    Dim D2ObjData As VBApi_TUniVal
    Dim ret As Long
    Dim value As Variant

' Initiation
    If Id = -1 And NumItems = -1 Then
        On Error GoTo InvalidParams
        value = UserParams(1) * 2 ' testing the parameter, it must be a number
        On Error GoTo 0
        Nasob = RetOk
        Exit Function
    End If

    If Id = NoDataTime Then
        Nasob = "No data"
        Exit Function
    End If

    If Id = NoDataValid Then
        Nasob = "Invalid data"
        Exit Function
    End If

    ret = GetActualD2DataObj(Id, D2ObjData) ' getting the current data
    If ret = RetOk Then
        On Error GoTo InvalidEnum
        value = D2GetSpecificProperty(D2ObjData, D2ValueValue) ' getting the value
        Nasob = value * UserParams(1) ' multiply by 2
        On Error GoTo 0
    Else
        Nasob = "No data"
    End If
    Exit Function

InvalidEnum:
    Nasob = "Calculation has failed"
    Exit Function

InvalidParams:
    Nasob = "Ask for parameter Number"
    Exit Function
End Function
Napíšte komentár