0

I have to columns, pipe material and pipe size, I only want to label pipes with a size greater than 2"

I am trying to do this but keeps kicking back and error, can anyone assist in what im doing wrong?

Function FindLabel ( [PIPE_MATERIAL] , [PIPE_INTERNAL_DIAMETER] )
  if ( [PIPE_INTERNAL_DIAMETER] > 2") then
   FindLabel = [PIPE_MATERIAL] 
  end if
End Function
0
Function FindLabel ( [PIPE_MATL], [PIPE_DIA] )
 ' this just pulls first digit from PIPE_DIA string 2", 3" & converts to Double type - you may have to play around with...  
   If CDbl( Mid([PIPE_DIA], 1, Len([PIPE_DIA])-1)) > 2 then
      FindLabel = [PIPE_MATL]
   else 
      FindLabel = ""
   end if
End Function

Adding unit decorations to a data field (like inch marks etc.) is always a BAD idea, poor database structure. The reason your code fails is your mixing data types in your "If" statement. You need to compare either 'all string' or 'all number' types.

|improve this answer|||||
  • cm1 - great that worked! Thanks alot! PS) The dataset was inherited from someone else I didnt create it. – Pob 1 Jul 15 '16 at 19:37
  • Great! If CDbl( Mid([PIPE_DIA], 1, Len([PIPE_DIA])-1)) > 2 then is probably better than If CDbl(Mid([PIPE_DIA], 1, 1))> 2 then I fully understand inheriting 'data badness'... good luck. – cm1 Jul 15 '16 at 19:45
  • You read my mind, I was just going to respond with it only showing sizes below double figures, but that follow up solved it :) many thanks again! – Pob 1 Jul 15 '16 at 19:49
0

I think it must be near your 'if ( [PIPE_INTERNAL_DIAMETER] > 2") then' line.

Your wanting to perform a logical mathematical operation there and the double quote after the 2" is probably getting in the way - getting interpreted as a string.

if PIPE_INTERNAL_DIAMETER is an integer field then you need to do something like:

Function FindLabel ( [PIPE_MATL], [P_INT_DIAM] )
if ( [P_INT_DIAM] > 2) then
  FindLabel = [PIPE_MATL]
end if
End Function
|improve this answer|||||
  • Hi, I tried adjusting it to Function FindLabel ( [PIPE_MATERIAL] , [PIPE_INTERNAL_DIAMETER] ) if ( [PIPE_INTERNAL_DIAMETER] > 2) then FindLabel = [PIPE_MATERIAL] end if End Function but still kicks back an error, the data type is double if that makes a difference – Pob 1 Jul 15 '16 at 16:22
  • What's the error message returned when you click the 'Verify' button? – cm1 Jul 15 '16 at 16:42
  • also it might be worth mentioning to you, that the pipe internal diameter columns actually have that unit value in them " ie inches 6" 4" 8" etc, is that gonna confuse things or is it still viable? – Pob 1 Jul 15 '16 at 16:46
  • The expression contains an error. Modify the expression and try again. Error 13 on line 2. Type mismatch: esri__1'. – Pob 1 Jul 15 '16 at 16:47
  • Try using single quotes: if ( [PIPE_INTERNAL_DIAMETER] > '2"' ) then – kenbuja Jul 15 '16 at 17:36
-1

I'm not really good with VB, so I'll offer a Python attempt. You would need to change from the Visual Basic parser to the Python parser and give something like this a try:

def FindLabel ( [PIPE_MATL], [PIPE_DIA] ):
  # assign pipe diameter string to S
  S = [PIPE_DIA]
  # trim the double-quote character from the end of the diam string/chg to float variable
  if (float(S[:-1]) > 2.0):
    return [PIPE_MATL]
  else:
    return ''

Be sure to keep the indentations intact if you cut-&-paste this. Whitespace/indentation is important/means 'run this block of code together' to Python.

|improve this answer|||||
  • Im running 10.0 the only parser options I have is Jscript & vb :( – Pob 1 Jul 15 '16 at 18:48

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.