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

Using TableNext to loop through tables

This source code snippet requires TX Text Control ActiveX
Author:TX Text Control Support Department
Language:Visual Basic 6
Version:1.0
Released:February 17, 2006
Last modified:January 11, 2008
Requirements:TX Text Control ActiveX with Visual Basic 6
Download code:tx_table_loop.zip Download [2.62 KB, ZIP]

In this sample application, we want to demonstrate how to loop through tables in a document with the TableNext function.

TableNext is different in using it compared to FieldNext, as there are two return values:

  1. i = TXTextControl1.TableNext(i, curTableID)

Variable i is the next enumeration number, that will be used for looping through all tables, and not the related TableID. Instead, TableNext will set curTableID to the corresponding table identifier of the enumeration number.

The function uses enumeration numbers because table identifiers are not unique and can change.

If i has been set to 0, the first table identifier (TableID) and the next enumeration number of the following table are returned.

To use this sample, simply click on File and Create Table Document. A document containing two tables is created on the fly. After that, click on Populate Tables and all cells in all tables in the document are filled with their positions in the tables.

  1. Dim i, j, k, curTableID As Integer
  2. i = 0
  3. 'Loop for the tables
  4. Do
  5. 'The TableNext function uses i (Enumeration for the tables) to get curTableID
  6. 'Please note that the return value is the enumeration number and NOT the TableID!
  7. i = TXTextControl1.TableNext(i, curTableID)
  8. 'if the enumeration number is 0, all tables have been processed.
  9. If i = 0 Then Exit Do
  10. 'Loop through the table rows
  11. For j = 1 To TXTextControl1.TableRows(curTableID)
  12. 'Loop through the table columns
  13. For k = 1 To TXTextControl1.TableColumns(curTableID)
  14. 'Set the TableCellText
  15. TXTextControl1.TableCellText(curTableID, j, k) = "Row" + Str(j) + ", Column" + Str(k)
  16. Next
  17. Next
  18. Loop

The minimum requirements for this sample application are TX Text Control ActiveX trial version and Visual Basic 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