Correct syntax for evaluating integers in If statements

1036
8
09-12-2019 12:04 PM
bobwright
Occasional Contributor

Greetings,

I am trying calculating a field based on an If statement: if(selected(${section},'>=1'),${town},${permit_area}). However, this does not appear to be working because it always produces the false response (${permit_area}). If I do this: if(selected(${section},'1'),${town},${permit_area}) and set ${section} to 1, it produces the true response (${town}. I'm assuming it's a syntax error in the former and I've tried everything I can think of. I do not get error messages with either of these approaches. The evaluation attribute (${section}) is integer. I have tried it with the field I am trying to calculate defined as string and with no definition. Any help would be greatly appreciated.

Bob

0 Kudos
8 Replies
DougBrowning
MVP Esteemed Contributor

If I follow I think your issue is that drop down lists are always strings.  So using a >=1 makes no sense.

The way it is written you are asking if the string '>=1' has been selected.  

0 Kudos
bobwright
Occasional Contributor

Hi Doug,

Thanks for the response. It is straight data entry, or a feed from Explorer for ArcGIS. See below. If the user enters a value for Section, then I want to calculate the field of interest (hidden) with Township ($). If Section is missing, I want to populate the field of interest with DPA. All are of type Integer. Does that help any?

Bob

0 Kudos
DougBrowning
MVP Esteemed Contributor

The selected command is for drop downs not data entry.  And I think all drops downs are string.  So you are kinda losing me.

0 Kudos
bobwright
Occasional Contributor

Sounds like the Select option is the wrong approach, but if so, I’m not sure why a specific value works. (I did try it Section as a string format.) Here is what I am trying to do: “If there is a legitimate value for Section, then the location resolution ($) is “TRS”; otherwise it is “DPA”.

0 Kudos
DougBrowning
MVP Esteemed Contributor

If you mean just check if it is blank then

if(${section}="",${town},${permit_area})

If section is a number I think you have to do this if I remember right.  Yea I know string length on a number but until it is filled in it is blank.

if(string-length(${section})=0,${town},${permit_area})

0 Kudos
LanceCole
MVP Regular Contributor

bob wright

Two suggestions:

  1. "section" is a reserved word in XMLForms.  If that is the name of your selection type or text box you may want to use something different such as "section_num"
  2. try using the following assuming you are checking against a select_one field or text box:

if(${section_num} >= 1, ${town}, ${permit_area})

This will return {town} for any value grater than 1 if it is selected/input in {section_num} and {permit_area} if zero or less.  I am not quite sure if you are using a dropdown or text field.

bobwright
Occasional Contributor

Lance Cole I did try the code you suggested with ${section}, but was still getting error messages. I did not know section was reserved, hence the unexplained squirreliness. Your suggestion to use something else worked. Thanks!

0 Kudos
DougBrowning
MVP Esteemed Contributor

Opps missed the Reserved Word.  Note that in Excel on the Types tap it lists all the reserved words for you.

0 Kudos