| Skype: | TextControlSupport | |
| Orders: | 877-462-4772 |

| 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 |
| Download code: | into_report.zip |
TX Text Control can be used in bound mode in Visual Basic (Delphi does not provide this feature), but this is not always the way to go. For example: You want to built an application that has a mail merge feature, but you do not want TX Text Control to replace the entire contents of the document with a field from a database. You need to replace only a certain piece of text or a marked text field with text from a database. This weeks Tip of the week shows how to do that.
Private Sub GetRecord() Dim ba() As Byte, s As String If IsNull(rs("RTF")) Then TXTextControl1 = "" TXTextControl2 = "" Else ' Load RTF data and convert it to a byte array s = rs("RTF") ba = StrConv(s, vbFromUnicode) ' Display RTF data in TX Text Control 1 TXTextControl1.LoadFromMemory ba, 5, False TXTextControl1.Refresh ' Display RTF source code in TX Text Control 2 TXTextControl2.Text = s End If End Sub ' ' PutRecord ' ' Save contents of TX Text Control to database ' Private Sub PutRecord() Dim ba() As Byte, s As String ba = TXTextControl1.SaveToMemory(5, 0) s = StrConv(ba, vbUnicode) rs.Edit rs("RTF") = s rs.Update End Sub
The two methods above are from the DataAccess sample, which you can download from our FTP server. The variable rs is a usual VB RecordSet. This example uses RTF rather than the internal TX format. GetRecord reads a field from the database and displays it in a TX Text Control. First the field 'RTF' is read into a string. Then StrConv is used to convert the string to a byte array (note the UniCode support) and then the byte array is loaded into the TX using LoadFromMemory.
If you do not want to replace the entire contents of the TX with the text from the database you simply have to specify 'True' for the last parameter. Then only the current selection is replaced. PutRecord works just the other way round and uses to SaveToMemory and StrConv to complete the task.