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
artwork21
35.2k8 gold badges69 silver badges135 bronze badges
asked Jul 15, 2016 at 15:43

3 Answers 3

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.

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
answered Jul 15, 2016 at 19:31
3
  • cm1 - great that worked! Thanks alot! PS) The dataset was inherited from someone else I didnt create it. Commented Jul 15, 2016 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. Commented Jul 15, 2016 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! Commented Jul 15, 2016 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
answered Jul 15, 2016 at 16:09
6
  • 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 Commented Jul 15, 2016 at 16:22
  • What's the error message returned when you click the 'Verify' button? Commented Jul 15, 2016 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? Commented Jul 15, 2016 at 16:46
  • The expression contains an error. Modify the expression and try again. Error 13 on line 2. Type mismatch: esri__1'. Commented Jul 15, 2016 at 16:47
  • Try using single quotes: if ( [PIPE_INTERNAL_DIAMETER] > '2"' ) then Commented Jul 15, 2016 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.

answered Jul 15, 2016 at 18:27
1
  • Im running 10.0 the only parser options I have is Jscript & vb :( Commented Jul 15, 2016 at 18:48

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.