Returning output based on number range

User-to-User discussion about the PhraseExpress macro programming.
Forum rules
Please read the forum disclaimer. Thank you!
Post Reply
Jeff
Posts: 21
Joined: 07 Sep 16, 01:23

Returning output based on number range

Post by Jeff » 09 Dec 17, 23:31

Support encouraged me to post this here as a macro question. Goal to return text output based on number within range of 0-100. This refers to Oswestry scores for low back disability.

{#settemp -name score -content 44}{#check -text {#gettemp score} -case < 21 -output minimal disability|< 41 -output moderate disability|< 61 -output severe disability|< 81 -output crippling back pain|< 101 -output bed-bound or exaggerated}

Output (correct) in v12 "severe disability", in v13 .60f output "bed-bound or exaggerated" (incorrect)

It appears in v12 the first true conditional generated the output whereby at that point additional conditionals were not checked, whereas in v13 the output is from the last true conditional, as it appears the check command continues processing the conditionals if another conditional was already true (or something to that effect).

I'm not sure what is the more correct behavior 12 versus 13, but is there a better macro technique to get the correct answer in v13?

Peter Stotz
PhraseExpress Expert
Posts: 611
Joined: 27 Feb 08, 15:07

Re: Returning output based on number range

Post by Peter Stotz » 10 Dec 17, 23:25

Hi Jeff,
the condition checks of the #check-macro are processed from left to right.
v12: the #check-macro had executed the -output operation of the first matching condition.
v13: the #check-macro executes the -output operation of the last matching condition.
For this reason, score value 44 leads in your example to the result "bed-bound or exaggerated".
{#settemp -name score -content 44}{#check -text {#gettemp score} -case < 21 -output minimal disability|< 41 -output moderate disability|< 61 -output severe disability|< 81 -output crippling back pain|< 101 -output bed-bound or exaggerated}

This check-macro should work properly:

Code: Select all

{#check -text {#gettemp score} -case < 1 -output Oswestry score lower limit: 1|> 0 -output minimal disability|> 20 -output moderate disability|> 40 -output severe disability|> 60 -output crippling back pain|> 80 -output bed-bound|> 100 -output Oswestry score upper limit: 100 -else}
You can try it with this macro:

Code: Select all

{#settemp -name score -content {#input -head Oswestry score: -single -def 44 -required numbers}}{#gettemp score} –> {#check -text {#gettemp score} -case < 1 -output Oswestry score lower limit: 1|> 0 -output 1÷20 - minimal disability|> 20 -output 21÷40 - moderate disability|> 40 -output 41÷60 - severe disability|> 60 -output 61÷80 - crippling back pain|> 80 -output 81÷100 - bed-bound|> 100 -output Oswestry score upper limit: 100 -else}
Peter
Win 10-1607 64 bit - PhraseExpress 13.0.60i

Jeff
Posts: 21
Joined: 07 Sep 16, 01:23

Re: Returning output based on number range

Post by Jeff » 11 Dec 17, 18:27

Thank you very much Peter, that fixes my issue.

Peter Stotz
PhraseExpress Expert
Posts: 611
Joined: 27 Feb 08, 15:07

Re: Returning output based on number range

Post by Peter Stotz » 30 Jan 18, 20:03

PhraseExpress 13.0.74 - redesigned #check-macro
Hi Jeff,
it seems with the last modification the developers have barked up the wrong tree ...
The #check-macro has been redesigned again, see
changelog 01/26/2018 13.0.74 http://www.phraseexpress.com/docs13/09/changelog.php
'Improved #check macro function.'
http://www.phraseexpress.com/docs13/09/macro.htm#check
"Nested Macro functions are interpreted from inner to outer macros. Beginning with PhraseExpress v13 {#CHECK …} macro branches are interpreted after the comparison."
In my opinion, this means the following:
Within the #check-macro, nested macros are processed from inside to outside and from left to right - the first matching condition from the left is executed (so the conditions can be used in a similar way to the previous versions).
Oswestry #check-macro for version 13.0.74i:
{#check -text {#gettemp score} -case > 100 -output Oswestry score upper limit: 100|> 80 -output 81÷100 - bed-bound|> 60 -output 61÷ 80 - crippling back pain|> 40 -output 41÷ 60 - severe disability|> 20 -output 21÷ 40 - moderate disability|> 0 -output 1÷ 20 - minimal disability|< 1 -output Oswestry score lower limit: 1}
or alternatively:
{#check -text {#gettemp score} -case < 1 -output Oswestry score lower limit: 1|< 21 -output 1÷ 20 - minimal disability|< 41 -output 21÷ 40 - moderate disability|< 61 -output 41÷ 60 - severe disability|< 81 -output 61÷ 80 - crippling back pain|< 101 -output 81÷100 - bed-bound or exaggerated -else Oswestry score upper limit: 100}

Peter
Win 10.0.16299 64 bit - PhraseExpress 13.0.74i

Post Reply