If-then label expressions using wildcard

3406
4
Jump to solution
07-18-2016 08:28 AM
deleted-user-yFo_UoWEJbkc
New Contributor III


I have a feature class for fire stations, and I'm trying to label only those fire stations that have a ladder truck (based on the [APPARATUS1] field), but I can't get the wildcard expression to work. Conversely, when I use the = operator, it returns the value just fine ([ID] is the station number) and labels the appropriate station:

Function FindLabel ( [ID], [APPARATUS1] )

if ( [APPARATUS1] = "Ladder 100' Tiller" ) then

  FindLabel = "Station " & [ID] & vbnewline & [APPARATUS1]

end if

End Function

But when I try to catch all the stations with ladders, I only get syntax errors with the following wildcard expression:

Function FindLabel ( [ID], [APPARATUS1] )

if ( [APPARATUS1] LIKE "Ladder%" ) then

  FindLabel = "Station " & [ID] & vbnewline & [APPARATUS1]

end if

End Function

Any help in figuring out what I'm missing would be much appreciated. I've tried various combinations of single-quotes, asterisk wildcard character, etc., but nothing works. Thanks!

0 Kudos
1 Solution

Accepted Solutions
JonMorris2
Occasional Contributor II

The LIKE keyword is for SQL queries. In VB, you need to do something similar to:

     If ( InStr( [APPARATUS1], "Ladder" ) <> 0 ) Then

This is case sensitive; to make the comparison case insensitive, you can use:

     If ( InStr( LCase([APPARATUS1]), "ladder" ) <> 0 ) Then

View solution in original post

0 Kudos
4 Replies
JonMorris2
Occasional Contributor II

The LIKE keyword is for SQL queries. In VB, you need to do something similar to:

     If ( InStr( [APPARATUS1], "Ladder" ) <> 0 ) Then

This is case sensitive; to make the comparison case insensitive, you can use:

     If ( InStr( LCase([APPARATUS1]), "ladder" ) <> 0 ) Then

0 Kudos
deleted-user-yFo_UoWEJbkc
New Contributor III

Thanks so much, Jon. This is exactly what I was looking for! I didn't realize LIKE wasn't a VB operator. One quick additional question: what would be the best way to include an OR statement so that the expression includes "Ladder" and "Tower" (two different kinds of aerial apparatus)?

0 Kudos
JonMorris2
Occasional Contributor II

I think you can just copy and paste the whole expression, e.g.

     If ( InStr( [APPARATUS1], "Ladder" ) <> 0 OR InStr( [APPARATUS1], "Tower" ) <> 0 ) Then

My VB is a bit rusty though, I mostly use python these days.

deleted-user-yFo_UoWEJbkc
New Contributor III

Right again, sir, and yes, I need to move past VB myself. Nevertheless, thanks for your help on this.

0 Kudos