I'm scratching my head at this; I have an Arcade expression used to drive interstate labels that I'm trying to copy over to a label class for US highway labels. In the DOT's STATE_ROUTE fields, these are notated as 'I' and 'US' - for example, 'STATE OF IOWA, I 74 W' or 'STATE OF IOWA, US 6 W'. My expression finds those strings within the field and then returns the appropriate numbered route, if any. However, when I swap the I for US, I get an invalid expression error - wrong number of arguments. I'm not changing the number of arguments, though, and it works fine in the interstate label class. I feel like I'm missing something obvious, but I can't figure it out. I'm just copying the expression over.
Here is the (functional) expression used for interstates:
IIF(Find('STATE OF IOWA, I',$feature.STATE_ROUT)>='0',Split($feature.STATE_ROUT, ' ', 5, true)[4],IIF(Find('STATE OF IOWA, I',$feature.STATE_RO_1)>='0',Split($feature.STATE_RO_1, ' ', 5, true)[4]))
It successfully returns the digits of an interstate, such as '80' or '380'. If I swap the 'STATE OF IOWA, I' portions for 'STATE OF IOWA, US', it kicks me the error message. Same exact string otherwise.
I tried removing the label class and trying again with a new label class (did not work). I then tried closing and reopening the project, and now I'm even getting the error when copying it verbatim. Still comes up as valid in the original interstate label class.
The 'wrong number of arguments' turned out to be referring to the final IIF (my bad, but not that it tells you that...), but I'm really curious as to why it would have worked just fine for my interstate labels and not US highways. It seems it shouldn't have worked for interstates, either.
Glad you found the error.
Some IDEs only tell you the line where something went wrong, not the exact position. So while it can be satisfying to write one-liners (I'm very guilty of that in Python) they make it hard to find the problem (plus, they are hard to read, and line-wrap doesn't make it better...).
if(Find('STATE OF IOWA, I', $feature.STATE_ROUT) > -1) {
return Split($feature.STATE_ROUT, ' ', 5, true)[4]
}
if(Find('STATE OF IOWA, I', $feature.STATE_RO_1)> -1) {
return Split($feature.STATE_RO_1, ' ', 5, true)[4]
}
return 'DefaultValue'
You're right, the expression shouldn't work for interstates, either. I have not the faintest clue why it would have worked, but:
Yes, it kept revalidating and was displaying my labels perfectly (see screenshot of validated expression above). I've corrected it now just in case, and now won't revalidate if I put it back. Strange!
Also, yes - I typically use variables, maybe more than necessary. They're nice, and certainly would have helped here.
This is a much happier (and easier to modify/reuse) solution.
//route field
var p = $feature.STATE_ROUT
//route type notation
var n = 'STATE OF IOWA, I '
//searches route field for type match, returns number only
IIF(Find(n,p)>='0',Split(p, ' ', 5, true)[4],'')