table search, table search vertically

Prev Next

Function Names

table search, table search vertically

Description

The table will be searched until the first (or next) pattern is matching the comparison expression.
table search searches the table horizontally line by line. To include header row, specify 0 as starting row number, otherwise 1 (or a bigger number if needed).
table search vertically searches the table vertically through the columns and then proceeding to the right. In this case, searching at the next colum begins at row 1 downward and not with the header row.

Attention: All values from the table being compared are strings, even if they contain numbers.

Call as: procedure or function

Restrictions

Indirect parameter passing is disabled

Parameter count

4-6

Parameters

No.TypeDescription
1.
input
string Name of existing table

2.
code
comparison expression
:string
Value compared with the table contents

This parameter is a piece of code typically found on the right-hand side of a comparison with '=' or '<>'. Single values, ranges (e.g. 3..5), multiple values separated by commas are supported. For text comparison, wildcards are supported if the string is of type softquoted string.

3.
io
numeral Row number

The row number is considered the starting row number for the search. When a match has been found, then the corresponding row number will be returned.

4.
io
numeral Column number

The column number is considered the starting column number for the search. When a match has been found, then the corresponding row number will be returned.

Opt. 5
input
table column Column representing left boundary for searching

See table columns as function parameters for general ruling for this parameter.
Specific rules apply for this function:

  • Specify exactly one header name or column number where to start searching and comparing from left to right

Default value: 0 (1st column)
Opt. 6
input
table column Column representing right boundary for searching

See table columns as function parameters for general ruling for this parameter.
Specific rules apply for this function:

  • Specify exactly one header name or column number where to stop searching and comparing from left to right

Default value: 0 (1st column)

Return value

TypeDescription
boolean Match found

true if match has been found, otherwise false.

Examples

       table initialize( table 1,
               { { A,  B,  C,  D,  E,  A,  G },
                 { E,  C,  D,  B,  A,  H,  X },
                 { T,  E,  B,  C,  A,  E,  A  } } );

       row[] = 0; col[] = 0;
       echo("Search entire table");
       while ( table search( table 1, (A), row[], col[] ) = true)
       {
               echo("Row: ", row[], "  Col: ", col[]++ );
       }

       row[] = 0; col[] = 0;
       echo("Search entire table vertically (Attention: begins at row 1 at next column");
       while ( table search vertically( table 1, (A), row[], col[] ) = true)
       {
               echo("Row: ", row[]++, "  Col: ", col[] );
       }

       row[] = 0; col[] = 0;
       echo("Limit search to column 1 - 4:");
       while ( table search( table 1, (A), row[], col[], B, E ) = true)
       {
               echo("Row: ", row[], "  Col: ", col[]++ );
       }

Output

Search entire table
Row: 0  Col: 0
Row: 0  Col: 5
Row: 1  Col: 4
Row: 2  Col: 4
Row: 2  Col: 6
Search entire table vertically (Attention: begins at row 1 at next column
Row: 0  Col: 0
Row: 1  Col: 4
Row: 2  Col: 4
Row: 2  Col: 6
Limit search to column 1 - 4:
Row: 1  Col: 4
Row: 2  Col: 4
Try it yourself: Open LIB_Function_table_search.b4p in B4P_Examples.zip. Decompress before use.

See also

table search header row