IBM®
Skip to main content
    Country/region select      Terms of use
 
 
   
     Home      Products      Services & solutions      Support & downloads      My account     

developerWorks  >  Lotus  >  Forums & community  >  Best Practice Makes Perfect

Best Practice Makes Perfect

A collaboration with Domino developers about how to do it and how to get it right in Domino

I noticed someone in the forums complaining that the Notes client didn't have any option to reverse the case of text, and it occurred to me that it shouldn't be too difficult to write an agent or action button to do this. I've done it two ways, one to change all the text in the Body field, one to do selected text only.
Here's the one to change the whole Body field. Note this assumes nobody is writing in the Kaithi alphabet, which is used temporarily to represent lowercase letters while we find and replace the uppercase letters to lowercase.

Dim aCode%, i%, savedMailOptions
aCode =
Uni("a")

Dim
wksp As New NotesUIWorkspace
Dim
session As New NotesSession
Dim
uidoc As NotesUIDocument, uidocNew As NotesUIDocument
Dim
doc As NotesDocument
Dim
rti As NotesRichTextItem
Dim
strFieldname As String

Set
uidoc = wksp.CurrentDocument
uidoc.Refresh
True ' do this if rich text field is editable, to get current contents in case user has modified them.
Set
doc = uidoc.Document  ' get the back-end document for the document open on screen.
Set
rti = doc.GetFirstItem("Body") ' insert your fieldname here, generally "Body"

Dim
range As NotesRichTextRange
Set
range = rti.CreateRange
Dim
count&, ch$
For
i = 0 To 25
       ch =
UChr(acode+i)
       count = range.FindandReplace(ch,
UChr(11080+i), RT_REPL_ALL)
       
Call range.FindandReplace(UCase(ch), UChr(acode+i), RT_REPL_ALL)
       
If count Then
               
Call range.FindandReplace(UChr(11080+i), UCase(ch), RT_REPL_ALL)
       
End If
Next

rti.Update


doc.SaveOptions =
"0" ' make it possible to close document without save prompt.
If
doc.HasItem("MailOptions") Then
       savedMailOptions = doc.GetItemValue(
"MailOptions")
End
If
doc.ReplaceItemValue
"MailOptions", "0"

Call
uidoc.Close(True)
Set
uidocNew = wksp.EditDocument(True, doc, , , , True)
Delete
uidoc
Set
doc = uidocNew.Document
doc.RemoveItem(
"SaveOptions")
If
Not IsEmpty(savedMailOptions) Then
       doc.ReplaceItemValue
"MailOptions", savedMailOptions
Else

       doc.RemoveItem
"MailOptions"
End
If

If one did want to operate on selected text only, that's simpler to do because there are UI methods for it, but unfortunately, you lose any formatting changes within the selected text, and any non-text objects, such as embedded images or tables. You also lose the distinction between line breaks and paragraph breaks, which normally doesn't matter. But for what it's worth, here it is:

Dim wksp As New NotesUIWorkspace
Dim
uidoc As NotesUIDocument
Dim
toFix$, i%, ch$, bChanged As Boolean
Set
uidoc = wksp.Currentdocument
toFix = uidoc.getselectedtext

For
i = 1 To Len(toFix)
       ch =
Mid$(toFix, i, 1)
       
If UCase(ch) <> LCase(ch) Then
               
If ch = UCase(ch) Then
                       
Mid$(toFix, i, 1) = LCase(ch)
               
Else
                       
Mid$(toFix, i, 1) = UCase(ch)
               
End If
               bChanged =
true
       
End If
Next

If
bChanged Then
       uidoc.InsertText toFix

End
If

Andre Guirard | 10 February 2010 02:08:12 PM ET | Home, Plymouth, MN, USA | Comments (1)

Search this blog 

Disclaimer 

    About IBM Privacy Contact