HOW TO

Include table fields in a VBScript label expression and use those values as dynamic font properties

Last Published: April 25, 2020

Summary


[O-Image] UK Flag
This article was contributed by Esri UK.

The instructions provided describe how to use dynamic values of font properties (font type and size) in a VBScript label expression.

Procedure



  1. Open the layer's attribute table.
    Right-click the layer in the Table of Contents and select Open Attribute Table.

    [O-Image] Open Attribute Table
  2. Add the following fields for the font and label properties.
    In the attribute table, click the table options button and select Add Field.

    [O-Image] Add New Fields
    Name: TextSize
    Type: Double
    [O-Image] TextSize
    Name: FontType
    Type: Text
    [O-Image] FontType
    Name: Label
    Type: Text
    [O-Image] Label
  3. In ArcMap, open Layer Properties and click the Labels tab.

    To open Layer Properties, double-click the layer in the Table of Contents or right-click the layer and select Properties.

  4. Click the 'Label features in this layer' checkbox and click the Expression button.
    [O-Image] Expression

  5. Type the following into the Expression text box:

    Code:
    "<FNT name='" & [FontType] & "' size='" & [TextSize] & "'>" & [Label] & "</FNT>"


    Note:
    Make sure that all of the single and double quotes (' and ") are included. Otherwise, there may be errors or labels are not displayed properly.

  6. Verify that the parser is set to VBScript.
    [O-Image] Label Expression


    Note:
    The label expression can be verified by entering the following sample test string in the Expression text box and clicking Verify.

    Code:
    "<FNT name='Arial' size='10'>ABC</FNT>"


    [O-Image] Sample Test String
  7. Click OK to close the Layer Properties window and to apply the settings. The map refreshes and the labels display according to the values stored in the attribute fields.

    Note:
    Make sure that the font type(s) chosen are installed on the machine. Otherwise, the labels may not display or may display incorrectly using a substitute font type.

Article ID:000011537

Software:
  • ArcMap

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Related Information

Discover more on this topic