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

How to create a MS Word-like letter wizard

This source code snippet requires TX Text Control ActiveX
Author:TX Text Control Support Department
Language:Visual Basic
Version:1.1
Released:March 20, 2001
Last modified:January 11, 2008
Requirements:TX Text Control ActiveX with Visual Basic 6.0
Download code:letter_wizard.zip Download [14.69 KB, ZIP]

Part #1

This example requires the Microsoft tabbed dialog control.

Continuing with our tutorial of how to implement Microsoft Word like features using TX Text Control, we are going to show you how to add a 'letter wizard' to your word processing application.

When it is finished, our letter wizard will allow the end user to efficiently and quickly create letters using information that he or she inputs in a form. The collected information is then inserted into the current TX Text Control document.

We shall be looking at the letter wizard over two weeks. Today, in the first of two parts, we are going to create the form which allow the input of data into TX Text Control.

We are going to use the TX Text Control's SelText methods to carry out this procedure. As only these easy-to-understand methods are going to be used, we have not published any source code here - for that, simply take a look at the file below for the complete listing.

Once the user has filled in each field on our form, he or she has all the data need to create the letter.

Next week, in the second step, we are going to show you how the single elements in the letter can be replaced.

Part #2

This week we are continuing with the second part of our Letter Wizard.

The next step of our sample application involves inserting fields as Marked Text Fields so that we can change what we have inserted at a latter point in time. Only once we have implemented this feature is our Letter Wizard really usable.

When we are done, you will be able to open a dialog box, enter data into the pre-defined fields, click on a button and then the data that you entered will be inserted into the letter. However, as we are now dealing with Marked Text Fields, you will be able to add, expand and remove all the data fields at will at any point after the data has been inserted.

The Field_Insert() function inserts the fields from the dialog box into the active TX Text Control - i.e. into your letter. Once we have done that, the function Field_Merge() fills out these fields with the data that we entered into the dialog box. Fields which are not filled out in the dialog box are still inserted, but with empty strings, so that they can get a value later on.

To simply the processing of the single fields we have built in another feature to our example: By clicking with the right mouse button on one of the Marked Text Fields, a pop-up menu appears which shows all the possible values for that field. Selecting one of them inserts that value in to the currently active document.

We used the MouseDown event to create this example. Here is the Visual Basic code:

  1. Private Sub TXTextControl1_MouseDown(Button As Integer, Shift As
  2. Integer, X As Single, Y As Single)
  3.  
  4. If Button = 2 Then
  5. TXTextControl1.SelStart = TXTextControl1.InputPosFromPoint(X, Y)
  6.  
  7. FieldId = TXTextControl1.FieldAtInputPos
  8. If FieldId = 0 Then Exit Sub
  9. TXTextControl1.FieldCurrent = FieldId
  10.  
  11. If TXTextControl1.FieldData(FieldId) = "closing" Then
  12. Form1.PopupMenu mnu_closing, , X, Y
  13. End If
  14.  
  15. If TXTextControl1.FieldData(FieldId) = "salutation" Then
  16. Form1.PopupMenu mnu_salutation, , X, Y
  17. End If
  18.  
  19. If TXTextControl1.FieldData(FieldId) = "reference_line" Then
  20. Form1.PopupMenu mnu_reference, , X, Y
  21. End If
  22.  
  23. If TXTextControl1.FieldData(FieldId) = "mailing_instructions" Then
  24. Form1.PopupMenu mnu_instructions, , X, Y
  25. End If
  26.  
  27. If TXTextControl1.FieldData(FieldId) = "attention" Then
  28. Form1.PopupMenu mnu_attn, , X, Y
  29. End If
  30.  
  31. End If
  32. End Sub

We use FieldAtInputPos to find out where the mouse currently is. If it is over one of our Marked Text Fields, a pop up menu is opened which contains all the possible entries for that field.

External verification page for ISO 9000:2000 certificate
ISO 9001:2000
certified