REM ***** BASIC ***** Sub Countchars ' Daniel Vogelheim wrote this ' displays a message box with number of characters and words in the current selection, and in the document ' ' get the document, and the currently selected text xDocument = thiscomponent xSelection = xDocument.getCurrentSelection() nSelCount = xSelection.getCount() ' access document statistics nAllChars = xDocument.CharacterCount nAllWords = xDocument.WordCount ' initialize counts nSelChars = 0 nSelWords = 0 ' iterate over multiple selection for nSel = 0 to nSelCount - 1 sText = xSelection.getByIndex(nSel).getString() ' count word in sText by scanning the selected text character for character nCount = Len(sText) bLastWasseparator = true 'first letter starts a word for i=1 to nCount Select Case Mid(sText,i,1) 'Add your own separators here 'chr(9) is a tab Case " ", "(", ")", chr(9) bLastWasseparator = true nSelChars = nSelChars + 1 'chr(10) and chr(13) are for Line- and Paragraph-ends 'Case chr(10), chr(13) bLastWasseparator = true 'Character found, so this is no separator Case Else 'Increase the number of words only if the last character was a separator '(i.e., if we're at the start of a word) if bLastWasseparator then nSelWords = nSelWords + 1 Endif nSelChars = nSelChars + 1 bLastWasseparator = false End Select next i next nSel ' Daniel Vogelheim's messagebox is the line commented out here. Mine is the uncommented one below it ' msgbox "Document" + chr(13) + " chars: " + nAllChars + chr(13) + " words: " + nAllWords + chr(13) + chr(13) + "Selection" + chr(13) + " chars: " + nSelChars + chr(13) + " words: " + nSelWords, 64, "Word counts in Document" msgbox "Document count:" + chr(13) + nAllWords +" words. " + chr(13) + chr(13) + "Selected text count:" + chr(13) + nSelWords + " words.", 64, "Words in Document" End Sub