XML Gauge Text, Part III: Mind your %'s and ('s

It looks like a common mistake made by people creating XML gauges is to use too many percent signs (%).  For example, I saw this in a 3rd-party gauge recently:

%{if} % (On)%{else} % (Off)%{end}

The underlined percent signs are unnecessary, and the parser will try to translate the "On" and "Off" as an expression that can be calculated.  Recall that "%( )" is used to calculate expressions; for example:

%((A:Eng1 Oil Pressure, PSF) 20 <)

would equate to TRUE or FALSE and could be used with the %{if} conditional above to conditionally display text.

Thus, the 3rd-party gauge should have used:

%{if}(On)%{else}(Off)%{end}

This above information is also covered in the SDK, an excerpt of which is pasted below:

Conditional Gauge Strings

The format of conditions (if, then, else, and case statements) in gauge strings is different from that in other scripts. In gauge strings use the %{if} , %{else} , and %{end} constructs to choose which text to display.  Note that these keywords are case-sensitive and must be typed in lowercase. Also, there must not be a space between the ‘ % ’ and the ‘ { ‘. An if statement can be used without a corresponding else, in which case nothing is displayed if the result of the condition is false. The syntax for usage is one of the following:

  • %(CONDITIONAL)%{if}TEXT TO DISPLAY IF TRUE%{else}TEXT TO DISPLAY IF FALSE%{end}
  • %(CONDITIONAL)%{if}TEXT TO DISPLAY IF TRUE%{end}

Comments

  • Anonymous
    January 01, 2003
    Great post, explained really well and I could really understand. Thank you.

  • Anonymous
    January 01, 2003
    PingBack from http://geeklectures.info/2008/01/14/xml-gauge-text-part-iii-mind-your-s-and-s/

  • Anonymous
    January 14, 2008
    Hi Susan, thank you for the clarification. I believe the misunderstanding exists because of the mode a var value is commonly displayed: %((MyVar) > 0)%!d! It could be "separated" in %((MyVar) > 0) and %!d! So it's important to highlight also that !operator! formatting must be preceeded by a % like %!s! or %!02d! or %!3.1f! I think this is not properly explained in SDK Regards, Tom

  • Anonymous
    January 16, 2008
    The comment has been removed

  • Anonymous
    September 08, 2008
    Hi I need to set up a <Visible> statement that evaluates (A:GPS APPROACH APPROACH ID, string) against a set of pre-defined strings such as 'VOR 21' 'LOC 31' etc. Please could you help me with the syntax required for the string 'VOR 21' Thanks Peter