Accessing Table Data 

The following code demonstrates techniques for accessing the data stored in a Table object.

 

Rem This example assumes that we have a table with 10 Rows and 5 Columns.

Dim vVal as VARIANT

Dim i as Long

Dim j as Long

Rem You can access each entry direct in the Table object

vVal = oTable.Value (1,1) ‘ or vVal = oTable(1,1)

Rem Alternatively, the column index can be a string

vVal = oTable.Value (1,"KUNNR") ‘ or vVal = oTable(1,"KUNNR")

Rem Setting a value works the same way

oTable.Value (1,1) = vVal

 

Rem You can access each entry of a table row using the Row object

Dim oRow as Object

Set oRow = oTable.Rows.Item (1) ‘ or Set oRow = oTable.Rows(1)

vVal = oRow.Value (1) ‘ or vVal = oRow(1)

Rem Alternatively, the column index can be a string

vVal = oRow.Value ("KUNNR") ‘ or vVal = oRow("KUNNR")

Rem Setting a value works the same way

oRow.Value (1) = vVal

 

Rem You can access each entry in a table column using the Column object.

Dim oColumn as Object

Set oColumn = oTable.Columns.Item(1) ‘ or Set oColumn=oTable.Columns(1)

vVal = oColumn.Value (1) ‘ or vVal = oColumn(1)

Rem Setting a value works the same

oColumn.Value (1) = vVal

 

Rem You can change the viewport to the table by using the Range object.

Rem The following line of code builds a Ranges collection in which

Rem each Range consists of 2 Rows of the Table

oTable.BuildTiledRanges (2)

Rem You can access each entry in a table range using the Range object

Dim oRange as Object

Set oRange = oTable.Ranges.Item(1) ‘ or Set oRange=oTable.Ranges(1)

vVal = oRange.Value (1,1) ‘ or vVal = oRange(1,1)

Rem Setting a value works the same way

oRange.Value (1,1) = vVal

 

Rem In order to speed up access to all data, the Data property

Rem is provided for each of the object types to be accessed.

Rem The following lines of code provide the standard technique for

Rem accessing all data in the table.

Dim vVal as VARIANT(10,5)

Dim i as Long

Dim j as Long

For i = 1 To Table.RowCount

For j = 1 To Table.ColumnCount

vVal (i,j) = Table.Value(i,j)

Next i

Next oRow

 

Rem By using the data property, the above code shrinks to one line:

Dim vVal as VARIANT

vVal = Table.Data

Rem Set values in the same way. Rows are added automatically,

Rem but columns are not.

Table.data = vVal

Rem The same works for a Row, a Column and a Range.

Dim oRow as Object

Dim oColumn as Object

Dim oRange as Object

Set oRow = oTable.Rows(1)

Set oColumn = oTable.Columns(2)

Set oRange = oTable.Ranges(3)

vVal = oRow.Data

vVal = oColumn.Data

vVal = oRange.Data

oRow.Data = vVal

oColumn.Data = vVal

oRange.Data = vVal