What's going on here is more subtle. 0123 means 123 base 8, so [incr 0123]
returns 84, which is correct. ALWAYS strip leading zeroes from numbers
you get from users, because if they put in something like 0789 and you
try to do:
if {$pin == 1234}
your script will blow up because $pin isn't a valid octal number.
A real pain, and easy to forget about.
If a thing is an arbitrary string, don't use if tests like the one
above; always use [string compare]. The other case that makes the
"if" above fail is something like:
set pin 12345678890123
if {$pin == "123"} {
...
TCL will first try to convert $pin to a number and an overflow will occur.
Only use if tests like the one above if you are positive that neither operand
could be interpreted as a number that may overflow.
Jim
>
> One thing about this is that you might want to include some code to trim any
> leading zeros. If the application asks for, say a PIN code, and the user
> inputs 0234, this function will return false because TCL will not add 1 to
> 0234, but it will add it to 234.
>
> Also, if you're looking for strict INTEGER validation (not just numeric
> validation), you'll want to check for any decimals and return false without
> testing the expression.
>
> In a message dated 8/9/2001 6:14:36 PM Eastern Daylight Time, [EMAIL PROTECTED]
> writes:
>
> > if {[catch {set res [expr $someVar + 1]}]} {
> > #someVar is not a number
> > } else {
> > # it is a number
> > }
> >
>