English

How To: Build a query expression based on a variable using Avenue

Summary

Instructions provided describe how to build a query expression based on a variable using Avenue. Below is an example of this function.

Procedure

The examples below assume the following:

Example 1
- A table with a numeric field called 'Class.'
- Desire to find all the records equal to '1.'
- A variable called 'selector' that equals '1.'

Example 2
- A table with a string field called 'State_Name.'
- Desire to find all the records equal to 'California.'
- A variable called 'selector' that equals 'California.'

  1. Open an new script window.

    A. Activate the Project window.
    B. Click the Scripts icon.
    C. Click New.

  2. Copy the following code into the script window:

    Example 1
    Code:
    thevtab = av.getactivedoc.getvtab
    thebitmap = thevtab.getselection
    selector = 1
    theExpress = "([Class] = "+ selector.asstring +")"
    thevtab.query(theExpress,thebitmap,#VTAB_SELTYPE_NEW)
    thevtab.updateselection

    Example 2
    Code:
    thevtab = av.getactivedoc.getvtab
    thebitmap = thevtab.getselection
    selector = "California"
    theExpress = "([State_name] = "+ selector.Quote +")"
    thevtab.query(theExpress,thebitmap,#VTAB_SELTYPE_NEW)
    thevtab.updateselection


  3. Click the Compile button.
    [O-Image] Script compile button
  4. Make the script and table windows visible.
  5. Make the table active.
  6. Click the script window.
  7. Click the Run button.
    [O-Image] Run compiled script button