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: 597
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 out 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.

Post Reply