2

This expression works perfectly when integer fields are 0 instead of NULL but now I am working with a GDB that has many NULL values. I'm not sure how to force CInt to only run if field is not null.

Error message

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
1

I found the correct way do handle this. If the field is Null then it will count as a 0. This first way is shorter although I'm not sure if it will give the desired result in every scenario.

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

  FindLabel = strInput
End Function

Alternatively....

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

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.