Skype:TextControlSupport
Orders:877-462-4772
TX Text Control - word processing components.
What is this?Syndicate this content

How to implement a 'Change Case' feature

This source code snippet requires TX Text Control ActiveX
Author:TX Text Control Support Department
Language:Visual Basic
Version:1.0
Released:July 15, 2005
Last modified:January 11, 2008
Requirements:TX Text Control ActiveX with Visual Basic 6
Download code:case_change_ocx.zip Download [3.05 KB, ZIP]

Implementing a 'Change Case' feature with TX Text Control

Click to enlarge

A desirable feature of a word processing application is to change the case of a word, sentence or entire document.

This sample application shows you, how to implement the different cases known from Microsoft Word in TX Text Control ActiveX.

We are going to implement the following case changes:

  • UPPER CASE
  • lower case
  • Title Case
  • tOgGlE cAsE
  • Sentence case.

The implementation is really simple. We just loop through the selected text and replace the current character with its newly specified case, without loosing the format. If the current character is to be converted to an upper case character, it is replaced using this simplified code:

  1. For i = mystart To (.SelStart + .SelLength - 1)
  2.  
  3. .SelStart = i
  4. .SelLength = 1
  5.  
  6. selChar = .SelText
  7.  
  8. Select Case CaseHandler
  9.  
  10. Case 1:
  11. changeText (LCase(.SelText))

To change the current character, we use the following function:

  1. Private Sub changeText(text As String)
  2. With TXTextControl1
  3.  
  4. .SelStart = .SelStart + 1
  5. .SelLength = 0
  6. .SelText = text
  7. .SelStart = .SelStart - 2
  8. .SelLength = 1
  9. .SelText = ""
  10.  
  11. End With

In Visual Basic, the functions LCase and UCase offer the functionality to change the case of characters.

In the sample application, you will see how the other cases are implemented and which constraints need to be followed.

The minimum requirements for this sample application are TX Text Control ActiveX trial version and Visual Studio 6.

top

Top 10 Bestselling Product Award 2007Top 25 Publisher Product Award 2007Top 10 Bestselling Product Award 2007 in JapanTop 25 Bestselling Product Award 2006Top 25 Bestselling Publisher Award 2006Reader's Choice Award, dot.net magazin, 3rd place