table lookup smart once ...

Prev Next

Function Names

table lookup smart once, table lookup smart once ignore case

Description

This function combines the benefits of table lookup smart() and table lookup once(). Every entry in the look-up table is referenced only once. with one following exception: The last row is exempted from that look-up-once rule, so you can specify a default row to capture all searches which have not been successful in the rows above.

Call as: procedure or function

Restrictions

Indirect parameter passing is disabled

Parameter count

6 - 8 (For parameter description and return values: see table lookup() )

Examples

  table load( lookup, "Examples/Table Lookup Example 2.csv" );

  table initialize( target,
       { { Preference,  Seats Needed, Location },
         { vegi pizza,   6, inside },
         { pizza tonno,  5, outside },
         { hamburger,    2, inside },
         { beer,         1, bar },
         { fries,        2, "self-service" },
         { pasta napoli, 8, inside },
         { steak,       10, inside },
         { steak,        3, outside } } );

  count[] = table lookup smart once ignore case
            ( target,   {Seats Needed, Preference,Location}, { Place to go, Phone, Row },
                      lookup,   {Table size,   Offering,  Ambience}, { Restaurant Name, Phone Number, '#row' }, true, Counter );

  echo("Lookup table:");
  table list( lookup );

  // Note: Every item in the lookup table is retrieved once. At next lookup, the next matching entry further below will be retrieved.
  // Exception: Last row, so you can use it as a default row to capture all lookups which failed further up.

  echo("Target table after lookup (", count[], " items found):");
  table list( target );

Output

Lookup table:
    0 : Offering           | Table size | Ambience               | Restaurant Name       | Phone Number   | Counter
    1 : *Chicken*          | 2,4,6      | inside,bar             | Rôtisserie de Paris   | (212) 555-1234 |        
    2 : *Curry*            | 1..10      | "self-service"         | Bharat take-away      | (212) 555-2345 |        
    3 : *Pizza*,*Pasta*    | 4,6,8      | inside,outside         | Luigis                | (212) 555-3456 | 1      
    4 : *Beer*,*Wine*      | *          | bar                    | Luigis                | (212) 555-3456 | 1      
    5 : *Pizza*,*sea*food* | *          | inside,outside         | All-Italian Trattoria | (212) 555-4567 | 1      
    6 : *Fish*,*sea*food*  | 2..8       | outside                | Wharf Place           | (212) 555-5678 |        
    7 : *Burger*,Fries     | 1..20      | =inside,"self-service" | Mr. Burgermeister     | (212) 555-6789 | 1      
    8 : *                  | 1..6       | *                      | Mom cooks for you     | Mom's number   | 1      
    9 : *                  | *          | *                      | Not found             | --             | 3      

Target table after lookup (8 items found):
    0 : Preference   | Seats Needed | Location     | Place to go           | Phone          | Row
    1 : vegi pizza   | 6            | inside       | Luigis                | (212) 555-3456 | 3  
    2 : pizza tonno  | 5            | outside      | All-Italian Trattoria | (212) 555-4567 | 5  
    3 : hamburger    | 2            | inside       | Mr. Burgermeister     | (212) 555-6789 | 7  
    4 : beer         | 1            | bar          | Luigis                | (212) 555-3456 | 4  
    5 : fries        | 2            | self-service | Mom cooks for you     | Mom's number   | 8  
    6 : pasta napoli | 8            | inside       | Not found             | --             | 9  
    7 : steak        | 10           | inside       | Not found             | --             | 9  
    8 : steak        | 3            | outside      | Not found             | --             | 9  

Try it yourself: Open LIB_Function_table_lookup_smart_once.b4p in B4P_Examples.zip. Decompress before use.

See also

table lookup smart
table lookup once
table lookup
table integrate smart once