1

I'm trying to show a label if a field + another field = a certain value. Not sure the proper way to do this. I've tried cint([field1]) + cint([field2]) = x but that doesn't work either. It says the expression is valid but the feature that meets the criteria is not labelled.

Function FindLabel ( [SQFT_CONC] , [DEPTH_CONC] , [SQFT_ASPHT] , [DEPTH_ASHT]  )
  Dim strInput
  if [DEPTH_CONC] + [DEPTH_ASHT] = 10 then
     strInput = "IT WORKS"
  end if

  FindLabel = strInput
End Function
3
  • 1
    what happens when you try this? what version of ArcGIS Desktop?
    – Midavalo
    Sep 17, 2016 at 2:22
  • ArcGIS 10.4.1 - It says the expression is valid but the feature that meets the criteria is not labeled.
    – Ryan
    Sep 17, 2016 at 2:24
  • There is an edit button beneath your question so that you can update it with any requested clarifications like this.
    – PolyGeo
    Sep 17, 2016 at 5:00

2 Answers 2

4

CInt should have worked for you - I wrote mine slightly different, but it works:

Function FindLabel ( [SQFT_CONC] , [DEPTH_CONC] , [SQFT_ASPHT] , [DEPTH_ASHT]  )
  Dim strInput
  Dim dc
  Dim da
  dc = CInt([DEPTH_CONC])
  da = CInt([DEPTH_ASHT])
  val = dc + da
  if (val = 10) then
     strInput = "IT WORKS"
  end if

  FindLabel = strInput
End Function

I'd also recommend you look into using Python parser for labelling - I find you have a bit more control of things using python.

def FindLabel ([SQFT_CONC] , [DEPTH_CONC] , [SQFT_ASPHT] , [DEPTH_ASHT]  ):
  if int([DEPTH_CONC) + int([DEPTH_ASHT]) == 10:
    return "IT WORKS!!"
  else:
    return ""

To treat Null values as 0 check for Null and substitute a 0 into the variable.

Function FindLabel ( [SQFT_CONC] , [DEPTH_CONC] , [SQFT_ASPHT] , [DEPTH_ASHT]  )
  Dim strInput
  Dim dc
  Dim da
  if isNull([DEPTH_CONC]) then
    dc = 0
  else
    dc = CInt([DEPTH_CONC])
  end if
  if isNull([DEPTH_ASHT]) then
    da = 0
  else
    da = CInt([DEPTH_ASHT])
  end if
  val = dc + da
  if (val = 10) then
     strInput = "IT WORKS"
  end if

  FindLabel = strInput
End Function

To ignore records completely, step over them in an if statement if either value is Null

Function FindLabel ( [SQFT_CONC] , [DEPTH_CONC] , [SQFT_ASPHT] , [DEPTH_ASHT]  )
  Dim strInput
  Dim dc
  Dim da
  if not isNull([DEPTH_CONC]) and not isNull([DEPTH_ASHT]) then
    dc = CInt([DEPTH_CONC])
    da = CInt([DEPTH_ASHT])
    val = dc + da
    if (val = 10) then
       strInput = "IT WORKS"
    end if
  end if
  FindLabel = strInput
End Function
8
  • Thank you! This will be much easier to implement. CInt did end up working for me in the end though, I'm not really sure what I messed up in my previous attempts.
    – Ryan
    Sep 17, 2016 at 3:00
  • Now I have an issue, what do I do when I have fields that are null? I get an error when I verify my expression.
    – Ryan
    Sep 19, 2016 at 13:39
  • @Ryan I'll update my answer shortly when I'm back in the office
    – Midavalo
    Sep 19, 2016 at 18:03
  • @Ryan how would you like to treat the Null fields? As if they were 0, or ignore the record completely?
    – Midavalo
    Sep 19, 2016 at 18:04
  • as if they were 0, I figured out how to do it , out of curiosity how would I ignore those records completely?
    – Ryan
    Sep 19, 2016 at 18:47
1

I'm not sure why it didn't work the first time I tried it this way but seemed to do the trick the 10th time around?

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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