English

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

Summary

Note:
The information in this article applies to ArcView GIS versions 3.x only. The instructions described apply to the Avenue programming language, which is specific to the ArcView GIS application.

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.
    1. Activate the Project window.
    2. Click the Scripts icon.
    3. Click New.
  2. Copy the code into the script window:
Example 1
thevtab = av.getactivedoc.getvtab 
thebitmap = thevtab.getselection 
selector = 1 
theExpress = "([Class] = "+ selector.asstring +")" 
thevtab.query(theExpress,thebitmap,#VTAB_SELTYPE_NEW) 
thevtab.updateselection
Example 2
thevtab = av.getactivedoc.getvtab 
thebitmap = thevtab.getselection 
selector = "California"
theExpress = "([State_name] = "+ selector.Quote +")" 
thevtab.query(theExpress,thebitmap,#VTAB_SELTYPE_NEW) 
thevtab.updateselection
  1. Click the Compile button. [O-Image] Script compile button
  2. Make the script and table windows visible.
  3. Make the table active.
  4. Click the script window.
  5. Click the Run button. [O-Image] Run compiled script button