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)


 Comments

1) The i18n /l10n police want to talk to you
Richard Schwartz | 2/10/2010 11:20:27 PM

The first method doesn't just presume that nobody is writing in the Kaithi alphabet. It also presumes nobody cares about changing the case of any accented or non-Roman characters.

2) Sorry, but...
Edson Viana | 2/11/2010 6:14:47 AM

You know that a software that has 20 years of development and improvement should already have that functionality years ago. It is almost unacceptable that, when you write and e-mail or a report, you have to delete what you typed wrongly and write it all over again. Just ridiculous. And suggesting a code to workaround it that runs on-demand, and not automatically, doesn't solve anything.

Good luck.

3) I tried using word as the email editor but,
Penny Whittaker | 7/8/2016 6:13:14 AM

Hi, Can you explain how I can create an action button to converted selected text with your 2nd script please?

I tried using the Word Memo option. I set Word as the Alternate Message editor. Then selected advanced menus. Create and new Word Memo. I could not attach items or use any other message function. Switching the text into Microsoft Word and using Shift F3 is not very user friendly. I tried creating an agent using your script but I don't have access. Next I tried to create an Action button but I don't know how to use your script. I tried pasting it into the formula area but it does not work. I am sorry that other users of this forum think it is OK to be abusive to developers offering solutions. I am grateful if you can help me.

4) There’s not a lot a non-Designer can do...
Andre Guirard | 7/8/2016 9:38:46 AM

It sounds like you hace less than Designer access to the database, which will make it impossible to add LotusScript code to it. There are ways around this which are complicated, based on being able to write whatever code you like in a database you create. But it might be simpler to write an Eclipse plugin to do this, assuming you have the Standard client. Then you can add it to the toolbar.

 Add a Comment
Subject:
   
Name:
Comment:  (No HTML - Links will be converted if prefixed http://)
 
Remember Me?     Cancel

Search this blog 

Disclaimer 

    About IBM Privacy Contact