Restricting User Input
Page 2 of 2

Author:  Cruncher [ Fri Oct 23, 2015 5:51 pm ]
Post subject:  Re: Restricting User Input

ElderProphet wrote:
I can shed some light on this.

First thing, I think you need something to follow the IF test, before the ELSE... try throwing a comment in there.

Secondly, in many programming languages, logic tests are short-circuited... which is to say, if the first argument needs to be true, but isn't, then nothing else is tested. And you can extrapolate that short-circuit behavior on and on... if an argument fails its test, nothing further is tested... in many programming languages.

So, Vid's statement would be fine... except TWX scripts DO NOT short-circuit logic tests. So let's recap:
> isNumber $yn $number
> if ($yn =TRUE) AND ($value > 0)
So indeed, the first argument fails if it's not a number... but the second comparison will still be attempted, and throw an exception if $value isn't a number. Make sense? I tried to alter this behavior, but it was non-trivial, and I don't think I succeeded.

So, you have to nest any comparisons that require a number inside of the isNumber test:
isNumber $yn $number
if ($yn = TRUE)
  if ($value > 0) // now it's safe, we verified it
    echo "Mathematical!!"

Cruncher, why wouldn't you want the number zero to pass the isNumber test? You may be creating the zero just by testing a value. Share more, and I'll elaborate if it applies.


Thanks EP

The number I'm testing is a ship number, cannot equal "0".

Author:  Adept [ Sat Oct 01, 2016 7:38 am ]
Post subject:  Re: Restricting User Input

Yea, just to note on this subject, it seems the script will crash if you attempt to compare a string to a number, so numbers have to be confirmed first (using isNumber) and then their ranges tested in a nested if--AND/OR--end. That is to be safe anyways.

Page 2 of 2 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group