Domino Code Fragment

Code Name*
Script Libraries - Examples
Date*
04/28/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.18.226.169.94
Description*
Script Libraries - Examples
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:
In R4.5 you can create script libraries that are available to all scripts in a database.
To use a library, just include a statement like this one in the Declarations section of
the script:

Use "Generic"

The following are a few handy functions you might want to keep in a generic script library.

   Function ReplaceWhitespaceWithPlusSigns( s As String ) As String
  Function ReplacePlusSignsWithSpaces( s As String ) As String
  Function IsWhiteSpace( s As String ) As Variant
  Function NewlineChar() As String
  Function TabChar() As String
  Function GetDbName( dominoUrl As String ) As String
  Function GetServerName( dominoUrl As String ) As String
  Sub PrintItemValues( doc As NotesDocument, web As Variant )
  Function ExtractParameter( paramName As String, queryString As String )


' This function replaces spaces, newlines and tabs with plus signs. This is useful
' when you are generating a URL.
Function ReplaceWhitespaceWithPlusSigns( s As String ) As String
Dim n As Integer, c As Integer
n = Len( s )
For i = 1 To n
If ( IsWhitespace( Mid( s, i, 1 ) ) ) Then
Mid( s, i, 1 ) = "+"
End If
Next
ReplaceWhitespaceWithPlusSigns = s
End Function


' This function replaces plus signs with spaces. This is useful when you are
' parsing a URL.
Function ReplacePlusSignsWithSpaces( s As String ) As String
Dim n As Integer, c As Integer
n = Len( s )
For i = 1 To n
If ( Mid( s, i, 1 ) = "+" ) Then
Mid( s, i, 1 ) = " "
End If
Next
ReplacePlusSignsWithSpaces = s
End Function


' This function checks the first character of a string and returns True if
' that character is a tab, space, or newline character, False otherwise.
' This function is used by ReplaceWhitespaceWithPlusSigns().


Function IsWhiteSpace( s As String ) As Variant
Const UNI_SPACE = 32
Const UNI_TAB = 9
Const UNI_RETURN = 10
Dim c As String
Dim u As Long
c = Mid( s, 1, 1 )
u = Uni( c )
If ( u = UNI_SPACE Or u = UNI_TAB Or u = UNI_RETURN ) Then
IsWhiteSpace = True
Else
IsWhiteSpace = False
End If


End Function

' This function returns a newline character.

Function NewlineChar() As String
NewlineChar = UChr(10)
End Function


' This function returns a tab character.

Function TabChar() As String
TabChar = UChr(9)
End Function


' This function extracts the database path/filename from a Domino URL
Function GetDbName( dominoUrl As String ) As String
Dim strLen, lastPos, startPos, endPos, i As Integer
Dim c As String, tmpString As String
strLen = Len( dominoUrl )
lastPos = strLen - 1
startPos = 8 ' Assumes the server name is preceded by "http://"
c = Mid( dominoUrl, startPos, 1 )
While ( c <> "/" And c <> "\" & startPos < lastPos )
startPos = startPos + 1
c = Mid( dominoUrl, startPos, 1 )
Wend
startPos = startPos + 1
tmpString = Mid( dominoUrl, startPos, ( strLen - startPos ) + 1 )
strLen = Len( tmpString )
lastPos = strLen - 1
endPos = InStr( tmpString, ".nsf" ) + 3
GetDbName = Mid( tmpString, 1 endPos )
End Function


' This function extracts the server name from a Domino URL
Function GetServerName( dominoUrl As String ) As String
Dim strLen, lastPos, startPos, endPos, i As Integer
Dim c As String
strLen = Len( dominoUrl )
lastPos = strLen - 1
startPos = 8 ' Assumes the server name is preceded by "http://"
endPos = 8
c = Mid( dominoUrl, endPos, 1 )
While( c <> "/" And c <> "\" & endPos < lastPos )
endPos = endPos + 1
c = Mid( dominoUrl, endPos, 1 )
Wend
GetServerName = Mid( dominoUrl, startPos, endPos - 8 )
End Function


' Prints the values of each item in a document
Sub PrintItemValues( doc As NotesDocument, web As Variant )
Dim newline As String
If ( web ) Then
newline = "<BR>"
Else
newline = NewlineChar()
End If
Forall item in doc.Items
Print item.Name & ":" & newline
Forall v in item.Values
Print v & newline
End Forall
Print newline
End Forall
End Sub


' This function extracts a parameter value from a URL query string
Function ExtractParameter( paramName As String, queryString As String )
Dim startPos As Integer, endPos As Integer
Dim paramLabel As String
paramLabel = paramName & "="
startPos = InStr( queryString, paramLabel )
' First make sure the parameter is really there
If ( startPos = 0 ) Then
ExtractParameter = ""
Exit Function
End If
' Now increment the starting position past the parameter label
queryString = Mid( queryString, startPos )
startPos = InStr( queryString, "=" ) + 1
queryString = Mid( queryString, startPos )
' Trim off everything that comes after this parameter
endPos = InStr( queryString, "&" )
If ( endPos = 0 ) Then
ExtractParameter = queryString
Exit Function
End If
endPos = endPos - 1
ExtractParameter = Mid( queryString, 1 endPos )
End Function