Compare strings do not have <= or >= options.

57 views
Skip to first unread message

ndrorian

unread,
Jan 29, 2019, 10:46:57 AM1/29/19
to MIT App Inventor Forum

From the three compare operations in AI2 the following two do not have <= or >= options.



Screen Shot 2019-01-29 at 7.38.35 AM.png

So, I tried using the blue compare from the math pallet  but that does not work for text fields? 


See block code and Runtime error. I think there are other ways of accomplishing the objective but I also think this is a limitation in AI2.


Screen Shot 2019-01-29 at 7.28.46 AM.png


Screen Shot 2019-01-29 at 7.36.02 AM.png


TimAI2

unread,
Jan 29, 2019, 10:51:59 AM1/29/19
to MIT App Inventor Forum
Use an "OR" block, one for compare: less than/greater than, and one for equals to ?
Message has been deleted

ndrorian

unread,
Jan 29, 2019, 3:18:11 PM1/29/19
to MIT App Inventor Forum
Here is the rewrite of the SANITIZE procedure. 

Screen Shot 2019-01-29 at 12.15.29 PM.png


Evan Patton

unread,
Jan 30, 2019, 2:18:27 AM1/30/19
to MIT App Inventor Forum
Tim is correct here. You can combine the greater/less than comparison with an equal comparison using a boolean OR block. The blue math block will attempt to parse the values as numbers before doing a comparison. Note that these have different semantics:

"200" string< "3" = true
"200" number< "3" = false

When you try to pass a string that isn't also readable as a number, the math block will fail with the error you show.

Regards,
Evan

ndrorian

unread,
Jan 30, 2019, 1:16:02 PM1/30/19
to MIT App Inventor Forum
I knew that I can use an OR block.

My request was to improve the compare text block by adding <= and =>.

Thank you
Reply all
Reply to author
Forward
0 new messages