VBScript and visual specifications (Aviation)

The rules in a visual specification determine the way a calculated representation or calculated field is going to appear in your map based on the attributes you are using. Rules are defined using either or both of the following:

A Structured Query Language (SQL) query alone can be used to define the calculated representation, or you can also use a script to further refine the way features are symbolized. The script provides you with a way to assign symbols to results of the SQL query based on additional conditions (programmatic expressions). For example, you can assign features with one subtype of one symbol and features with another subtype of a different symbol.

VBScript expressions must be defined when you are creating rules for calculated fields. However, they are not required for calculated representations.

The fields available for use with the expressions are based on the fields included in the SELECT part of your SQL statement. If you only have one or two fields from your feature classes available for selection, only those two are going to appear in the Expression Parser for the Visual Specifications tool.

The conditions for symbolization and text strings are determined using if…else statements. The if part of the statement contains the feature attribute and the array of values you want to use in the condition. The else part of the statement represents a different condition that you want to apply to the symbolization and labels. An example follows:

if IsNull( [SRC_SUB_arr](0) ) then
  strSUB = ""
else
  strSUB = [SRC_SUB_arr](0)
end if
Generate = strSUB
End Function

The Expression Parser analyzes your SELECT statement and constructs the outline of a function, Generate, in which you can conduct additional processing of the query results. For each field specified in the SELECT clause of the query, the Generate function will contain two parameters:

If your query returns one result row per feature, you can ignore the array parameters in your VBScript code and just manipulate the scalar parameters to construct your calculated field.

In certain advanced cases, a query can return multiple result rows per feature. In those cases, your VBScript code can loop through the result rows using the array parameters to construct a multiline text string. To format a text string with multiple lines, you can include vbNewLine, vbCRLF, or Chr(13) + Chr(10).

The example below illustrates the use of array parameters and looping:

if IsNull( [SRC_SUB_arr](0) ) then
  strSUB = ""
else
  strSUB = [SRC_SUB_arr](0)
end if

if IsNull( [NAME as B_NAME_arr](0) ) then
  strNAME = ""
else
  strNAME = [NAME as B_NAME_arr](0)
end if

if IsNull( [COLOUR as B_COLOUR_arr](0) ) then
  strCOLOUR = ""
else
  strCOLOUR = [COLOUR as B_COLOUR_arr](0)
end if

if IsNull( [COLPAT_arr](0) ) then
  strCOLPAT = ""
else
  strCOLPAT = [COLPAT_arr](0)
end if

str1 = "Master: " + strSUB + "NAME: " + strNAME + " Color: " + strCOLOUR + " Pattern: " + strCOLPAT + Chr(13) + Chr(10)

For i = 0 To UBound([SRC_SUB_arr])
  if IsNull( [DEST_SUB_arr](i) ) then
    strSUB = ""
  else
    strSUB = [DEST_SUB_arr](i)
  end if

  if IsNull( [NAME as S_NAME_arr](i) ) then
    strNAME = ""
  else
    strNAME = [NAME as S_NAME_arr](i)
  end if

  if IsNull( [COLOUR as S_COLOUR_arr](i) ) then
    strCOLOUR = ""
  else
    strCOLOUR = [COLOUR as S_COLOUR_arr](i)
  end if

  str1 = str1 + "Slave: " + strSUB + "  NAME: " + strNAME + "  Color: " + strCOLOUR

  if IsNull( [LITCHR_arr](i) ) then
    strLITCHR = ""
  else
    strLITCHR = [LITCHR_arr](i)
  end if

  if Len( strLITCHR ) > 0 then
    str1 = str1 + "  LITCHR: " + strLITCHR
  end if

  if IsNull( [TOPSHP_arr](i) ) then
    strTOPSHP = ""
  else
    strTOPSHP = [TOPSHP_arr](i)
  end if

  if Len( [strTOPSHP] ) > 0 then
    str1 = str1 + "  TOPSHP: " + strTOPSHP
  end if
  str1 = str1 + Chr(13) + Chr(10)
Next
Generate = str1
End Function

Labeling features with domain descriptions in VBScript expressions

You can also display domain description text in attribute fields for labeling features through the VBScript Expression Parser. A special syntax is used to call the domain description stored in a field: $[<field_name>]. For example, boundary classifications in a map are stored in the Boundary_class attribute field as coded value domains with textual descriptions. To label the boundary areas with the domain descriptions, you can use the following syntax:

if [Boundary_class] = 0 then
 Generate = $[Boundary_class]
else
 Generate = $[Boundary_class]
end if
End Function

The boundary areas will be labeled as City and County.

Expressions and calculated representations

The expressions created using VBScript allow you to set conditions that determine the way symbols are represented based on a range of attributes or associated table values. For example, features with an FCsubtype value of 0 can be represented with one symbol, and features with any other subtype can be represented with another symbol:

if [FCsubtype] = 0 then
  reprule = "ESRI.Style::On Point"
else
  reprule = "ESRI.Style::Buffer Hatch"
end if

Generate = reprule
End Function

Expressions and calculated fields

With calculated fields, VBScript can be used to customize labels for features in the map. For example, you may want to use one font size for small cities' labels and a different font size for larger cities'.

Related Topics

12/22/2014