Page 1 of 1
Unruly scrollbar numberformat
Posted: Tue Feb 24, 2009 2:23 pm
by hamlynart
Hi Folks,
I'm a bit confused. I'm trying to get a three digit number out of a scrollbar by using the "numberformat" but for some reason it won't work? Any ideas? Here's my code:
Code: Select all
on mouseUp
set the numberformat to "000"
put the thumbPosition of scrollbar "scrollbar" into myVar
set the numberformat to "000"
answer myVar
end mouseUp
Many Thanks in advance.
Jim H
Posted: Tue Feb 24, 2009 2:45 pm
by hamlynart
Hi again,
Quote from the dictionary:
Important! Changing the numberFormat does not automatically change the format of a number that's already in a container. It affects numbers only when they are calculated and then displayed or used as strings. Otherwise, the number retains its full numeric precision.
I guess it's a case of RTFM! Anyway I've sorted it by adding 1 and then subtracting 1. Annoying, but at least it works.
Code: Select all
on mouseUp
set the numberformat to "000"
put the thumbPosition of scrollbar "scrollbar" into myVar
add 1 to myVar
subtract 1 from myVar
answer myVar
end mouseUp
Cheers
Jim H
Posted: Tue Feb 24, 2009 3:17 pm
by SparkOut
Hi Jim,
You might also find that the numberFormat is unnecessary.
Try
The help in the Rev dictionary is not
that intuitive, but it matches the C printf() function, so you may be able to look up some more depth on the formatting options.
The formatting code begins with %, the zero means "pad to length with leading zeroes", the 3 means the length of the output, the d means a "decimal number" (which is actually interpreted as "integer" and will be rounded).
will get you a string representation of a floating point number of length 7 (including the decimal point) so that would be padded to three zeros before the decimal point, and rounded to three decimal places precision after the point.
Posted: Fri Mar 13, 2009 7:09 pm
by bn
Hi Jim,
you might just as well code
Code: Select all
on mouseUp
set the numberformat to "000"
put the thumbposition of scrollbar "scrollbar" + 0 into myVar
answer myVar
end mouseUp
For the numberformat to go into effect it suffices to do any calculation, adding 0 is enough
regards
bernd