0

In a software that I am developing I have to allow a user to pick a document which is in .RTF format and load it in TX Text Control. Then extract data from each row (column 2) and save it to another TX Text Control.

The document in question contains one Table in which all the text is contained.

Here is the code that I am using to extract text from second Column of each Row:

With TXTextControl1

    .SetFocus
    .ResetContents
    .LoadSaveAttribute(txLoadImages) = True
    .Load fn, 0, 5
    DoEvents

    I = .TableNext(I, CurTableID)
    If CurTableID = 0 Then
      MsgBox "Document Format is NOT Proper", vbInformation, App.Title
      Screen.MousePointer = vbNormal
      Exit Sub
    End If

    For J = 1 To .TableRows(CurTableID) - 1 'Step 7 'Loop through all Rows
      .SelStart = .TableCellStart(CurTableID, J, 2) - 1
      .SelLength = .TableCellLength(CurTableID, J, 2)
      Debug.Print "Row: " & J, .TableColAtInputPos
      List1.AddItem "Row: " & J & " Col Cnt: " & .TableColAtInputPos & IIf(.TableColAtInputPos = 0, " <= Problem Here", "")
      TXTextControl2.SelText = J & vbCrLf
      TXTextControl2.RTFSelText = .RTFSelText
      TXTextControl2.SelText = vbCrLf
      DoEvents
    Next J
  End With

But this code seems to show inconsistent behavior of TX Text Control in selecting Cell contents. At times it is selecting the whole row instead of just the cell contents.

To demonstrate this inconsistent I have created a demo which can be downloaded from here.

Any ideas how to overcome this bug?

TIA

Yogi Yang

Yogi Yang 007
  • 5,147
  • 10
  • 56
  • 77
  • I'm not sure anyone has a clue what this control might be. Both posts that have this tag were yours and nobody answered. – Bob77 May 19 '14 at 21:31
  • You can't rely on answerers downloading demos to see what the problem is. Nobody is going to go to the trouble and security risk to install it to check your demo. So, pretend you have zero knowledge of your situation, have never seen TX Text Control before, and I'm describing the problem to you. It should be quickly clear that after I tell you "at times it is selecting the whole row instead of just the cell contents" you still have nowhere near the information you need to help me with the problem. Suppose you point out what code is supposed to do the selection and the expected behavior. – BobRodes May 21 '14 at 15:44

2 Answers2

1

Yes. Dump the "TX Text Control" and use the VB6 RTF control. You can trick this control into supporting later versions than 1.0 (it's crippled for backward compatibility with earlier versions of VB) by accessing the TOM directly. (I'm borrowing from this link for my explanation.)

Along with the RichTextBox reference you'll need to add a reference to TOM (if not listed as an available reference browse to riched20.dll).

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
  (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_USER = &H400&
Private Const EM_GETOLEINTERFACE = (WM_USER + 60)

Dim myIUnknown As IUnknown
Dim tomDoc As ITextDocument

SendMessage rtbText.hwnd, EM_GETOLEINTERFACE, 0&, myIUnknown
Set tomDoc = myIUnknown

This will get you a direct reference to the underlying implementation of TOM in the RTF control. ITextDocument is the top-level object, and here's Microsoft's TOM reference. Have fun! :)

BobRodes
  • 5,990
  • 2
  • 24
  • 26
  • Thanks for the tip. I will definitely check it out. But actually for this particular project adopting anything else is not possible as our client insisted that we use TX Text Control. – Yogi Yang 007 May 21 '14 at 06:04
  • Another question is: Does RTF as available with VB6 handle Tables in documents correctly? – Yogi Yang 007 May 21 '14 at 06:04
  • The VB6 RTF control uses the RTF 1.0 specification, unless you trick it to use a later one. You'll want to look up TOM, and see whether the latest version handles tables or not. I think it does, but I'll leave you to research it. The point is that using TOM allows you to access later versions of RTF. However, usually, TOM is a version or two behind the RTF version that Office uses, so you have to be a bit careful. – BobRodes May 21 '14 at 15:32
0

I have solved the problem in a different way.

What I did was opened the document in question in MS Word and added an extra Column after the first column and save the document.

Now I am loading the document in TX Text Control and deleting the added (second column) programmatically and then everything seems to work well.

My primary testing show that the problem is solved at least for the document in question.

Thanks everyone for your valuable tips, tricks and hints.

Regards,

Yogi Yang

Yogi Yang 007
  • 5,147
  • 10
  • 56
  • 77