|
|
|
|
|
|
Basic How To |
|
How To Implement Replaceable Fields |
It is easy to implement replaceable fields in ALLText, however ALLText does not support the same RTF fields as created in MS Word.
|
View On-Line Sample |
|
Return to main How To Page |
Using Tags to Implement Mail Merge / Replaceable Fields
ALLText provides a mechanism for Tagging phrases within an RTF document. We call these NTags and HTags. Any number of phrases may be tagged in a document and each phrase can have it's own unique tag ( a long integer number) or you can use the same tag multiple times in a document.
It's a simple matter to implement a Mail Merge type application using ALLText and Tagged Phrases ( see "Creating Tagged Phrases" below). Simply include some placeholder text in the document and tag it with either NTags or HTags.
Now to conduct a MailMerge you can use the FindNTag or FindHTag method in a loop to search for and select each tagged phrase. Then read the associated Tag and replace the selected text using either the SelText or SelFText properties.
Creating Tagged Phrases
There are two ways of creating Tagged Phrases...
- Use embedded codes
\ATXht#### - starts an HTagged phrase, #### is any long integer value \ATXht0 - ends an HTagged phrase
\ATXnt#### - starts an NTagged phrase, #### is any long integer value \ATXnt0 - ends an NTagged phrase these tags must be terminated by a space.
You can use these embedded codes within a file to be loaded into ALLText, or you can use them when creating or modifying a document programmatically.
To add embedded codes to an existing TXT or RTF document, open The document in Notepad or a similar text based editing tool ( Do not use MS Word or other RTF editor as this will treat embedded codes you type in as text, rather than as codes) Open the document and simply add the embedded codes as shown above.
To add embedded codes you can include them as part of a string assigned to the FText or SelFText properties
ALLText.SelFText = "Here is a sentence with \ATXht5 an HTagged \ATXht0 phrase"
ALLText.SelFText = "Here is a sentence with \ATXnt5 an NTagged \ATXnt0 phrase"
- Use the NTag and HTag properties while editing the document in ALLText Place a button or other interface element on your form. In the click event you can set the NTag or HTag property with any long integer value. This will apply the tag to any currently selected text.
SAMPLE CODE:
Private Sub Form_Load()
ALLText.FText = "\plain \fs20 \li4005 \cf1 \ATXnt1 Date \ATXnt0 \cf0 " _ & "\par \li0 \par \par \ATXnt3 Street Address\ATXnt0 " _ & "\par \ATXnt4 City, State \ATXnt0" _ & "\par\par Dear \ATXnt2 Name\ATXnt0 :" _ & "\par \par This is a form letter. " _ & "Here we will show how to handle Field Replacement inside ALLText"_ & "\par \par For further information please contact us atSupport_ALLText@Bennet-Tec.Com"
ALLText.WriteProtect = ATX_PROTECT_CHANGES
End Sub
Sub cmdReplace_Click()
Dim Ret_code&
Dim Done As Integer
Dim wp%
With ALLText
-
-
Screen.MousePointer = 1
-
-
wp% = ALLText.WriteProtect
-
-
.WriteProtect = 2
-
-
.Select = False
-
.SelStart = .TextLength - 1
-
-
Do Until Done = True
-
-
-
If .NTag <> 0 Then
-
-
Ret_code& = .FindNTag(0, 0)
-
Else
-
-
Ret_code& = .FindNTag(0, -1)
-
End If
-
-
Tag = .NTag
-
Select Case Tag
-
Case Is > 0
-
-
-
x = GetText(Tag)
-
.SelText = x
-
-
.NTag = Tag
-
-
.Select = 0
-
If .SelStart = 0 Then Done = True
-
Case Is = 0
-
Done = True
-
End Select
-
Loop
-
-
Screen.MousePointer = 0
-
-
.WriteProtect = wp%
-
End With
End Sub
Function GetText(ByVal WhatData As Long) As String
Dim Names(10) As String
Names(0) = "Mr. Big Jaws"
Names(1) = "Ms. Minnows"
Names(2) = "Captain Nemo"
Names(3) = "Little Mermaid"
Dim Streets(10) As String
Streets(0) = "50 Surf Road"
Streets(1) = "35 Waterloo Way"
Streets(2) = "1002 Little Pond Ave"
Streets(3) = "2 Big Ocean Place"
Dim Cities(10) As String
Cities(0) = "Montauk, NY"
Cities(1) = "SeaCliff, NY"
Select Case WhatData
Case 1 GetText = Format$(Now(), "dd mmm yyyy")
Case 2 GetText = Names(Int(Rnd() * 4))
Case 3 GetText = Streets(Int(Rnd() * 4))
Case 4 GetText = Cities(Int(Rnd() * 2))
End Select
End Function
|