Unruly scrollbar numberformat

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
hamlynart
Posts: 101
Joined: Wed Mar 19, 2008 7:10 pm
Contact:

Unruly scrollbar numberformat

Post by hamlynart » Tue Feb 24, 2009 2:23 pm

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

hamlynart
Posts: 101
Joined: Wed Mar 19, 2008 7:10 pm
Contact:

Post by hamlynart » Tue Feb 24, 2009 2:45 pm

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

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Post by SparkOut » Tue Feb 24, 2009 3:17 pm

Hi Jim,
You might also find that the numberFormat is unnecessary.

Try

Code: Select all

answer format ("%03d",myVar)
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).

Code: Select all

format ("%07.3f",myVar)
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.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Fri Mar 13, 2009 7:09 pm

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

Post Reply