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!
Solved! Go to Solution.
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
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
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)?
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.
Right again, sir, and yes, I need to move past VB myself. Nevertheless, thanks for your help on this.