Wednesday, October 29, 2008

LotusScript equivalents for the @Subset

Function Subset(array As Variant, n As Integer) As Variant
'Eqiv to @Subset
Dim retVal As Variant
Dim i As Integer
If Not Isarray(array) Then
Subset = array
Exit Function
End If
If n = 0 Then
Subset = ""
Exit Function
End If
If Abs(n) >= (Ubound(array) - Lbound(array) + 1) Then
Subset = array
Exit Function
End If
If n > 0 Then
Redim retVal(Lbound(array) To (Lbound(array) + n - 1)) As Variant
Else
Redim retVal((Ubound(array) - Abs(n) + 1) To Ubound(array)) As Variant
End If
For i = Lbound(retVal) To Ubound(retVal)
retVal(i) = array(i)
Next
Subset = retVal
End Function

LotusScript equivalents for the @Middle

Function Middle(fullString As String, startString As String, endString As String)
'Script equivalent to @Middle
startPosition = Instr(fullString, startString)
startLen = Len(startString)
If startPosition > 0 And startString <> "" Then
endPosition = Instr( Right$(fullString, (Len(fullString) - startPosition)), endString)
If endPosition > 0 Then
Middle = Mid$(fullString, (startPosition + startLen), _
Instr( (startPosition + startLen), fullString, endString) - (startPosition+ startLen) )
Else
Middle = Mid$ (fullString, (Instr(fullString, startString) + Len(startString)) , Len(fullString))
End If
Else
Middle = ""
End If
End Function

Tuesday, October 28, 2008

LotusScript equivalents for the @Word

Function Word (sourceString As String, separator As String, number As Integer) As String
'LotusScript equivalents for the @Word
searchString$=SourceString & separator ' add one separator to catch also the last substring
For i% = 1 To number
pos%=Instr(searchString$, separator)
If pos%=0 Then Exit For
substring$=Left(searchString$,pos%-1)
searchString$=Mid(searchString$, pos%+1)
Next
If pos% > 0 Then
Word=substring$
Else
Word=""
End If
End Function

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

Monday, October 27, 2008

LotusScript equivalents for the @Implode

Function ImplodeString(vInput As Variant, sDelimiter As String) As String
'LotusScript equivalents for the @Implode
If Datatype(vInput) < 12 Then
ImplodeString = vInput
Exit Function
End If

Forall vItem In vInput
If vItem <> "" Then sTmp = sTmp & vItem & sDelimiter
End Forall
If Right(sTmp,Len(sDelimiter)) = sDelimiter Then
ImplodeString = Left(sTmp, Len(sTmp) - Len(sDelimiter))
Else
ImplodeString = sTmp
End If
End Function

LotusScript equivalents for the @Explode

Function Explode(Byval sInput As String, Byval sDelimiter As String) As Variant 
'LotusScript equivalents for the @Explode
Dim sOutput As String 
Dim aOutput() As String 
Dim nPos As Integer 
Dim nNextPos As Integer 
sOutput = sInput     
Redim aOutput(0)     
nPos = Instr(sOutput, sDelimiter) 
While nPos <> 0 
aOutput(Ubound(aOutput)) = Left(sOutput, nPos - 1) 
sOutput = Right(sOutput, Len(sOutput) - Len(sDelimiter) - nPos + 1) 
nPos = Instr(sOutput, sDelimiter) 
Redim Preserve aOutput(Ubound(aOutput) + 1) 
Wend 
aOutput(Ubound(aOutput)) = sOutput     
Explode = aOutput 
End Function