Tuesday, October 28, 2008

LotusScript equivalents for the @Dblookup

Function DBLookup(Byval strView As String, LookupValue As Variant, Byval iColumn As Integer) As Variant
DBLookup = Null

' Validate arguments

If Trim(strView) = "" Then Exit Function
If iColumn < 0 Then Exit Function
If Isnull(LookupValue) Then Exit Function

On Error Goto ErrorDBLookup

Dim keys(0) As String
Dim tmpStrArr(0) As String
Dim vResults As Variant

Dim vwEmp As NotesView
Dim tmpDoc As NotesDocument
Set vwEmp = DB.GetView(strView)

Forall LookupItem In LookupValue
keys(0) = LookupItem
Set tmpDoc = vwEmp.GetDocumentByKey(keys)
'If Isempty(vResults) Then Msgbox "Empty"

If tmpDoc Is Nothing Then
If Isempty(vResults) Then
tmpStrArr(0) = ""
vResults = tmpStrArr
Else
vResults = Arrayappend (vResults, tmpStrArr)
End If
Else
If Isempty(vResults) Then
tmpStrArr(0) = tmpDoc.ColumnValues(iColumn)
vResults = tmpStrArr
Else
vResults = Arrayappend (vResults, tmpDoc.ColumnValues(iColumn))
End If
End If
End Forall

DBLookup = vResults
Exit Function

ErrorDBLookup:
Msgbox "Error: libSystem: DBLookup: " + Chr(10) + "Report the problem to the application owner."
Exit Function
End Function

No comments: