Monday, December 8, 2008

LotusScript equivalents for the @Contains(@UserRoles;"ADMIN")

Function IsInRole (RoleName As String) As Integer
IsInRole = False
Dim userRoles As Variant
userRoles = Evaluate("@UserRoles")
Forall role In userRoles
If Ucase(role) = Ucase(RoleName) Then
IsInRole = True
Exit Forall
End If
End Forall
End Function

Monday, November 17, 2008

LotusScript equivalents for the @URLDecode

Function urlDecode(s As String) As String
If Len(s) = 0 Then Exit Function
Dim i As Integer
Dim tmp As String
Dim c As String
For i = 1 To Len(s)
c = Mid$(s, i, 1)
If c = "+" Then c = " "
If c = "%" Then
c = Chr$("&H" + Mid$(s, i + 1, 2))
i = i + 2
End If
tmp = tmp + c
Next i
urlDecode = tmp
End Function

LotusScript equivalents for the @URLEncode

Function urlEncode(s As String) As String
If Len(s) = 0 Then Exit Function

Dim tmp As String
Dim c As String
Dim i As Integer

For i = 1 To Len(s)
c = Mid(s, i, 1)
If (Asc(c) >= 65 And Asc(c) <= 90) _
Or (Asc(c) >= 97 And Asc(c) <= 122) _
Or (Asc(c) >= 48 And Asc(c) <= 58) _
Or Asc(c) = 38 _
Or (Asc(c) >= 45 And Asc(c) <= 47) _
Or Asc(c) = 58 Or Asc(c) = 61 _
Or Asc(c) = 63 Or Asc(c) = 126 Then
tmp = tmp + c
Else
tmp = tmp + "%" + Hex(Asc(c))
End If
Next i
urlEncode = tmp
End Function

Saturday, November 15, 2008

LotusScript equivalents for the @ProperCase

Function properCase(Byval txtIn As String) As String
properCase = Strconv(txtIn, 3)
End Function

LotusScript equivalents for the @ReplaceSubstring

Function ReplaceSubstringEvaluate (Byval fullString As String, oldString As String,
newString As String) As String
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim var As Variant

Set db = session.CurrentDatabase
Set doc = New NotesDocument(db)

Call doc.ReplaceItemValue("FullString", fullString)
Call doc.ReplaceItemValue("OldString", oldString)
Call doc.ReplaceItemValue("NewString", newString)

var = Evaluate("@ReplaceSubstring(fullString; oldString; newString)", doc)
ReplaceSubstringEvaluate = var(0)

'** clean up the memory we used
Set doc = Nothing
Set db = Nothing

End Function

Wednesday, November 12, 2008

LotusScript equivalents for the @Elements

Function Elements(anArray as Variant) as Integer
i = 0
Forall values in anArray
i = i + 1
End Forall
Elements = i
End Function

LotusScript equivalents for the @Replace

Function StringStuffReplaceString(strArg As String, strSrc As String,strDst As String) As String
Dim iPos As Integer
iPos = Instr(strArg, strSrc)
While iPos > 0
strArg = Left$(strArg, iPos - 1) + strDst + Mid$(strArg, iPos + Len(strSrc))
iPos = Instr(iPos + Len(strDst), strArg, strSrc)
Wend
StringStuffReplaceString = strArg
End Function

LotusScript equivalents for the @Picklist

Sub Click(Source As Button)
Dim ws as new notesuiworkspace
dim mailfile as string
dim mailserver as string
dim varFolder as variant


mailfile=ses.GetEnvironmentString( "MailFile", True) mailserver=ses.GetEnvironmentString( "MailServer", True)
varFolder=ws.PickListStrings( 4, False, mailserver, mailfile)

'False to select a single folder or specify True to select multiple folders by holding the Crtl-key

if isEmpty(varFolder) then exit sub

End Sub

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

Tuesday, November 4, 2008

LotusScript equivalents for the @Leftback

Public Function LeftBack(stringToSearch As String, param2 As Variant)
'This is an exact version of @LeftBack() in LotusScript
Const V_INTEGER = 2
Const V_STRING = 8
Const ErrTypeMismatch = 13

Dim v As Variant

If Datatype(param2) = V_INTEGER Then
Let v = Evaluate(|@LeftBack("| & stringToSearch & |"; | & param2 & |)|)
Elseif Datatype(param2) = V_STRING Then
Let v = Evaluate(|@LeftBack("| & stringToSearch & |"; "| & param2 & |")|)
Else
Error(ErrTypeMismatch)
End If

Let leftBack = v(0)

End Function

LotusScript equivalents for the @RightBack

Function RightBack (sourceString As String, searchString As String) As String
'LotusScript equivalents for the @RightBack
For i% = Len(sourceString) To 1 Step -1
sourceStringBack$=sourceStringBack$ & Mid(sourceString, i%, 1)
Next
For i% = Len(searchString) To 1 Step -1
searchStringBack$=searchStringBack$ & Mid(searchString, i%, 1)
Next
pos% = Instr ( sourceStringBack$, searchStringBack$)
If pos% > 0 Then pos% = pos% - 1
result$ = Left ( sourceStringBack$, pos%)
For i% = Len(result$) To 1 Step -1
turn$=turn$ & Mid(result$, i%, 1)
Next
RightBack=turn$
End Function

Monday, November 3, 2008

LotusScript equivalents for the @Ends

Function Ends (fullString As String, subString As String)
'Script equivalent to @Ends
If Instr ( Right$ (fullString, Len(subString)), subString) = 1 Then
Ends = True
Else
Ends = False
End If
End Function

LotusScript equivalents for the @Begins

Function Begins (fullString As String, subString As String)
'Script equivalent to @Begins
If Instr ( fullString, subString) = 1 Then
Begins = True
Else
'Begins is False
End If
End Function

Sunday, November 2, 2008

LotusScript equivalents for the @Left

Function LeftOf (sourceString As String, searchString As String) As String
'LotusScript equivalents for the @Left
pos% = Instr(sourceString, searchString)
If pos% > 0 Then pos% = pos% -1
LeftOf = Left(sourceString, pos%)
End Function

LotusScript equivalents for the @Right

Function RightOf (sourceString As String, searchString As String) As String
'LotusScript equivalents for the @Right
pos% = Instr(sourceString, searchString)
length% = Len(sourceString)
start% = length% - pos%
RightOf = Right(sourceString, start%)
End Function

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