1

If you're reading this for the first time, it might be best to focus on section beneath ANOTHER UPDATE.

I'm a beginner with VBScript and I have a question about using an VBScript expression for a label. I want to label street address numbers and the fractional address number, if it exists, in my map. This data is stored in an address points shapefile. I go Properties > Labels > Expression... in Esri software to enter this expression:

[HSE_NO]&" "& [FRAC_NO] 

With this expression the labels will be created next to the address points as follows:

 412 1/2 412

See how both labels are on the same line? I would like to have the labels look like this:

412
412 1/2

I want the first label to be the address value without a fraction, and the following lines would be address values with fractions. I welcome your suggestions.

UPDATE

I think what I need is more complex than I realized. As I mentioned, I want first label to be address street value (HSE_NO) without a fraction (where FRAC_NO is NULL). I'm working on getting this to occur with what's below. It's not correct! Any ideas?

Function FindLabel ( [HSE_NO], [FRAC_NO] )
if (IsNull[FRAC_NO]) then
    FindLabel = [HSE_NO] 
    End If
End Function

ANOTHER UPDATE

I have a point shapefile of addresses. Some address points contain the address number and street name. Some points contain address number, address fractional number, and street name. Points containing fractional values will overlap points containing not containing fractional values. I want to label these overlapping points like this:

1159
1159 1/2

My current VBScript labels addresses in this manner.

1159 1/2 1159

Does anyone know how to get the desired result? Here's my current expression:

Function FindLabel ( [HSE_NO], [FRAC_NO] )
  if (IsNull([FRAC_NO])) then
    FindLabel = [HSE_NO]
  else
    FindLabel = [HSE_NO] & " " & [FRAC_NO] 
  End If
End Function
  • Change the line FindLabel = [HSE_NO] & " " & [FRAC_NO] to FindLabel = [HSE_NO] & vbNewLine & [FRAC_NO] as shown in the examples below – kenbuja Jun 11 '12 at 17:36
  • I do not want a new line there. When I try the code you wrote, [HSE_NO] & vbNewLine & [FRAC_NO] I get this effect: 1159 and on next line: 1/2 – Patty Jula Jun 11 '12 at 18:18
  • Try the line FindLabel = [HSE_NO] & vbNewLine & [HSE_NO] & [FRAC_NO] – kenbuja Jun 11 '12 at 18:41
4

You should use vbNewline for this

Your expression should be

[HSE_NO] & vbNewLine & [FRAC_NO]

If you want to check if FRAC_NO is null, then you can use the following code

Function FindLabel ( [HSE_NO], [FRAC_NO] )
  IF (IsNull([FRAC_NO])) Then
    FindLabel = [HSE_NO]
  else
    FindLabel = [HSE_NO] & vbNewLine & [FRAC_NO] 
  End If
End Function

See these pages for more examples:

  1. Label expression by way of VBScript

  2. HowTo: Use advanced label expressions in ArcMap

3

Combine your updated code with what Devdatta provided:

Function FindLabel ( [HSE_NO], [FRAC_NO] )
  if (IsNull([FRAC_NO])) then
    FindLabel = [HSE_NO]
  else
    FindLabel = [HSE_NO] & vbNewLine & [FRAC_NO] 
  End If
End Function
  • Thank you for the suggestions. @kenbuja, the one set of parenthesis in your second line of code was very helpful. I have not yet found the desired solution, I put an update above. – Patty Jula Jun 11 '12 at 16:59
2

You may also use vbcrlf.

[HSE_NO] & vbcrlf & [FRAC_NO]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.