Select to view content in your preferred language

ArcGIS Pro 3.0.4 - Arcade 'if' statment syntax with variable?

413
4
Jump to solution
05-16-2023 04:26 AM
VincentLaunstorfer
Regular Contributor

Hi,

In an Arcade statment, I am losing patience on silly syntax in an 'if' statment, with condition to compare the first 3 digits of postal code with a variable stored in an array, as below:

if (Left(city.postal_code,3) == myArray[f]) {

The 'if' statment is simply ignored!

But if I hard-code a value, that's works fine:

if (Left(city.postal_code,3) == '332') {

 

Any guess where the problem is?

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

For your code to work, the value of myArray[f] must be a string. If it's a number, it won't work. You have to use this syntax if it's a number

if (Left(city.postal_code,3) == Text(myArray[f])) {

Here's a demo of that in the playground

playground.png

View solution in original post

4 Replies
JohannesLindner
MVP Frequent Contributor

Seems like myArray[f] is not equal to "332"...

That's all we can tell you from that snippet. If you want more detailed help, you'll have to post the whole expression.


Have a great day!
Johannes
KenBuja
MVP Esteemed Contributor

For your code to work, the value of myArray[f] must be a string. If it's a number, it won't work. You have to use this syntax if it's a number

if (Left(city.postal_code,3) == Text(myArray[f])) {

Here's a demo of that in the playground

playground.png

VincentLaunstorfer
Regular Contributor

Fantastic! Good to know array values has to be casted to text for 'if' statments... Very useful.

0 Kudos
KenBuja
MVP Esteemed Contributor

You have to cast the value array to Text since "Left(city.postal_code,3)" is also a Text.

0 Kudos