The @WebDBName function provides a quick way to get a reference to the current database in a format that can be used as a URL. I am working on an application that needed much the same thing except I needed a link to another Notes database. I decided to create a LS equivalent of the @WebDBName function that takes a single parameter. This parameter can be Nothing (current database), String (filepath of database) or a NotesDatabase object and returns the URL for that database. This function will be added to the next release of the Domino.@Functions namespace (possibly released on OpenNTF this weekend).
'/**
' * Returns the name of a Notes database encoded for URL inclusion.
' *
' * @author Peter Presnell
' * @param Source Database path - Nothing = current database
' */
Function atfWebDBName(Source As Variant) As String
Dim Filepath As String
Select Case Typename(Source)
Case "NOTESDATABASE"
FilePath$ = Source.FilePath$
Case "STRING"
FilePath$ = Cstr(Source)
Case "OBJECT"
FilePath$ = Session.CurrentDatabase.FilePath$
End Select
atfWebDBName$ = atfReplaceSubstring(FilePath$,Split("\\: ",":"),Split("/:%20",":"))
End Function
Note: In some cases an alternative to the above could be to use the NotesDatabase.HttpURL property.
The code for the atfReplaceSubstring (LS version of @ReplaceSubstring) is as follows:-
'/**
' * Replaces specific words or phrases in a string with new words or phrases that you specify
' *
' * @author Peter Presnell
' * @param Source he string whose contents you want to modify.
' * @param Search A list containing the words or phrases that you want to replace.
' * @param ReplaceTo A list containing the replacement words or phrases.
' * @return The sourceList, with any values from fromList replaced by the corresponding value in toList.
' * If none of the values in fromList matched the values in sourceList, then sourceList is returned unaltered.
' */
Function atfReplaceSubstring(Source As Variant, Search As Variant, ReplaceTo As Variant) As Variant
Dim Results As Variant ' Interim results
Dim Index As Long
Dim ReplaceToItem As Variant ' Replacement value for match
Try:
On Error Goto Catch
If Isarray(Source) Then
Redim Results(Lbound(Source) To Ubound(Source))
For Index& = Lbound(Source) To Ubound(Source)
Results(Index&) = atfReplaceSubstring(Source(Index&),Search,ReplaceTo)
Next Index&
atfReplaceSubstring = Results
Else
atfReplaceSubstring = Source
If Isarray(Search) Then
For Index& = Lbound(Search) To Ubound(Search)
If Isarray(ReplaceTo) Then
If Index& > Ubound(ReplaceTo) Then
ReplaceToItem = ReplaceTo(Ubound(ReplaceTo))
Else
ReplaceToItem = ReplaceTo(Index&)
End If
Else
ReplaceToItem = ReplaceTo
End If
atfReplaceSubstring = atfReplaceSubstring(atfReplaceSubstring,Search(Index&),ReplaceToItem)
Next Index&
Else
' Covert all parameters to strings
If Isarray(ReplaceTo) Then
ReplaceToItem = Cstr(ReplaceTo(0))
Else
ReplaceToItem = Cstr(ReplaceTo)
End If
Source = Cstr(Source)
Search = Cstr(Search)
' Locate each occurence of search item and replace with replacement item
If Search <> ReplaceToItem Then
While Instr(atfReplaceSubstring, Search) > 0
atfReplaceSubstring = Left$(atfReplaceSubstring, Instr(atfReplaceSubstring, Search) - 1) + ReplaceToItem +_
Right$(atfReplaceSubstring, Len(atfReplaceSubstring) - Instr(atfReplaceSubstring, Search) - Len(Search) + 1)
Wend
End If
End If
End If
Exit Function
Catch:
Stop
Call ReportError
Exit Function
End Function
1 Thomas Adrian Permalink Why not use: implode(Evaluate(|@webdbname|))
2 Thomas Adrian Permalink Sorry, I did not read the whole post before posting.
Never the less, if you learn to use Evaluate you do not need so
much code.
3 Thomas Adrian Permalink Strange, There is no way to unrecommend a comment.