Wednesday, November 5, 2008

LotusScript equivalents for the @Dbcolumn

Function Dbcolumn(s As NotesSession, servernm As String, dbname As String, vname As String, colno As Integer) As Variant
' this function retrieves a view's column values from the database (db) in a specified view
' this function returns the resulting values of the lookup as an array.

Dim Db As NotesDatabase ' lookup database
Dim lupV As NotesView ' lookup view
Dim eCol As NotesViewEntryCollection ' all entries in view
Dim e As NotesViewEntry ' entry of eCol
Dim tmpcount As Long ' counting variable for tmpArray
Dim tmpArray() As Variant ' values of lupItem in lupdoc(s)
Dim LSDbCol As Variant

On Error Goto LUpErrorHandler

' get database
Set Db=s.GetDatabase(servernm, dbname, False)
If (Db Is Nothing) Then
' return nothing
LSDbCol=""
Exit Function
End If
Set lupV=Db.GetView(vname)
If (lupV Is Nothing) Then
' return nothing
LSDbCol=""
Exit Function
End If

Set eCol=lupV.AllEntries
Set e = eCol.GetFirstEntry()
If (e Is Nothing) Then
' no entries in view, return nothing
LSDbCol=""
Exit Function
End If

' have entries, loop and add to new list
tmpcount=0
While Not (e Is Nothing)
' redim array
Redim Preserve tmpArray(tmpcount)
' get column value
tmpArray(tmpcount) = Cstr(e.ColumnValues(colno))
tmpcount=tmpcount + 1
Set e = eCol.GetNextEntry(e)
Wend

' return result
LSDbCol=tmpArray
Exit Function

LUpErrorHandler:
' print error to console
Print "(LSDbCol) Unexpected error: " & Error$ & " (" & Cstr(Err) & "), on line: " & Cstr(Erl)
' return nothing
LSDbCol=""
Exit Function

End Function

No comments: