I cannot get the below to work with a LIKE variable within the If/Then statement. Is there something that I am missing?
Prelogic Script
dim y
If [Categories] LIKE '%Orange%' Then
y = "Medium"
Else y = [Categories]
End If
Status =
y
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.
Sign up to join this communityI cannot get the below to work with a LIKE variable within the If/Then statement. Is there something that I am missing?
Prelogic Script
dim y
If [Categories] LIKE '%Orange%' Then
y = "Medium"
Else y = [Categories]
End If
Status =
y
There is no LIKE comparison operator in VB Script (see link).
You could use InStr to check if some search text appears somewhere in the input string:
dim y
If InStr([Categories], "Orange") Then
y = "Medium"
Else
y = [Categories]
End If
Status = y
InStr will return 0
if the search text is not found, which will be interpreted as False in the condition statement.
If you want to search some text explicitly in the begining of the input string, just check if the value returned from InStr is 1
.
If you want to search some text in the end of the input string, try Right function to extract part of the string and then do the comparison.
%
is SQL operator for LIKE clause. However, I would use python for the same calculation in one line, e.g.,"Medium" if "Orange" in !Categories! else !Categories!
– fatih_dur Jul 20 '18 at 1:16