Shifted Table Column Specifications

Prev Next

Introduction

In some situations, you know a specific column number for orientation, and want to use this column to reference a different column nearby, i.e. further to the left or to the right. In this case, provide the header name as softquoted string, for example with Text inside single quotation marks, and start the text with one or multiple '<' or '>' symbols. Multiple consecutive symobls can be cascaded to refer to nearby columns which are not immediate neighbors.

< Refer to the next column to the left. Example: '<First Name'
> Refer to the next column to the right. Example: '<State or Province'
<< Refer to 2 columns to the left left. Example: '<<First Name'
>> Refer to 2 columns to the left right.. Example: '<<State or Province'
<> The two symbols neutralize each other
>< Same here

Attention: The < and > symbols must be the 1st characters after the quotation marks. If spaces lie inbetween, then these symbols are considered as part of header names.
Attention: Shifting does not happen in quoted strings, e.g. ">Last Name". It assumes the header name containing the > symbol.


Left-shifting stops at column 0. Attempts to go beyond will also refer to column 0. Attempting to right-shift beyond the last column is OK as long the function allows it. Otherwise exceptions will be asserted, too.

Shifted table column specifications are supported referencing tables as well as in selected function parameters expecting table columns as function parameters.

  table initialize( t,  { { Col A, Col B, Col C, Col D, Col E, Col F },
                          { Val A, Val B, Val C, Val D, Val E, Val F, Val G } } );

  echo("Accessing the table directly:");
  echo( [ t: '<Col D', 1 ] ); // Col C
  echo( [ t: '>>Col D', 1 ] ); // Col F
  with table( t, 1 ) echo( [ '>Col A'] ); // Partial table specifcation used here, too.

  echo(new line, "And with function parameters:");
  echo( table read column selected rows ( t, Col B, true ) ); // Val B
  echo( table read column selected rows ( t, '<Col B', true ) ); // Val A
  // echo( table read column selected rows ( t, '<<Col B', true ) ); // would assert exception
  echo( table read column selected rows ( t, '<>Col B', true ) ); // Val B
  echo( table read column selected rows ( t, '>Col E', true ) ); // Val F
  echo( table read column selected rows ( t, '>>Col E', true ) ); // Val G
Accessing the table directly:
Val C
Val F
Val B

And with function parameters:
{'Val B'}
{'Val A'}
{'Val B'}
{'Val F'}
{'Val G'}
Try it yourself: Open LAN_Features_shifted_table_column_specification.b4p in B4P_Examples.zip. Decompress before use.