How To: Include table fields in a VBScript label expression and use those values as dynamic font properties
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.
- Open the layer's attribute table.
Right-click the layer in the Table of Contents and select Open Attribute Table.
- Add the following fields for the font and label properties.
In the attribute table, click the table options button and select Add Field.Name: TextSize
- 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.
- Click the 'Label features in this layer' checkbox and click the Expression button.
- Type the following into the Expression text box:
"<FNT name='" & [FontType] & "' size='" & [TextSize] & "'>" & [Label] & "</FNT>"
Make sure that all of the single and double quotes (' and ") are included. Otherwise, there may be errors or labels are not displayed properly.
- Verify that the parser is set to VBScript.
The label expression can be verified by entering the following sample test string in the Expression text box and clicking Verify.
"<FNT name='Arial' size='10'>ABC</FNT>"
- 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.
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.