I have 4 fields that hold number values. I only want a label returned if the field <>0. For instance, if col1<>0, then label = col1 AND if col2 <>0 then label = col2, etc. So, I want all four columns to show up as labels, but only if they are not equal to 0.
I have tried finding info online and am having issues. Thought maybe everyone could help.
The following script works, but only for one at a time. I need to combine them so that this script works with Seq2, Seq3 and Seq4. I am thinking there is a way to do multiple IF statements?
Function FindLabel ( [Seq1_TractDepthSequence], [Seq1_BegInterval] ,[Seq1_EndInterval], [Seq1_DeckCorpRITot], [Seq1_DeckCorpORRITot] , [Seq1_DeckCorpIntTot] , [Seq1_DeckCorpGWITot] )
if ( [Seq1_TractDepthSequence] = 1) AND ([Seq1_DeckCorpRITot] <> 0) then
FindLabel = [Seq1_BegInterval] &" - "& [Seq1_EndInterval] &" : "& [Seq1_DeckCorpRITot] &" RI"
end if
End Function
The following won't work:
Function FindLabel ( [_Seq1_TractDepthSequence], [_Seq1_BegInterval] ,[_Seq1_EndInterval], [_Seq1_DeckCorpRITot], [_Seq1_DeckCorpORRITot] , [_Seq1_DeckCorpIntTot] , [_Seq1_DeckCorpGWITot] )
if ( [_Seq1_TractDepthSequence] = 1) AND ([_Seq1_DeckCorpRITot] <> 0) then
FindLabel = [_Seq1_BegInterval] &" - "& [_Seq1_EndInterval] &" : "& [_Seq1_DeckCorpRITot] &" RI"
if ( [_Seq1_TractDepthSequence] = 1) AND ( [_Seq1_DeckCorpORRITot] <> 0) then
FindLabel = [_Seq1_BegInterval] &" - "& [_Seq1_EndInterval] &" : "& [_Seq1_DeckCorpORRITot] &" ORRI
if ( [_Seq1_TractDepthSequence] = 1) AND ( [_Seq1_DeckCorpIntTot] <> 0) then
FindLabel = [_Seq1_BegInterval] &" - "& [_Seq1_EndInterval] &" : "& [_Seq1_DeckCorpIntTot] &" CorpInt"
if ( [_Seq1_TractDepthSequence] = 1) AND ( [_Seq1_DeckCorpGWITot] <> 0) then
FindLabel = [_Seq1_BegInterval] &" - "& [_Seq1_EndInterval] &" : "& [_Seq1_DeckCorpGWITot] &" WI"
else
end if
End Function
Best Answer
The reason your code was failing was you had multiple "if" statements without an "end if" for each of them. It looks like you wanted "elseif" for the second, third, and fourth checks.
Since you're always checking whether the _Seq1_TractDepthSequence field is = 1, try something like this to condense the code.
Based on your comment below, try this code.