Page 1 of 2
little confused with the thumbPos of a slider
Posted: Sat Jul 14, 2012 7:39 pm
by jmburnod
hi All,
I'm a little confsed with the thumbPos of a slider.
I thought that I could add the thumbPos of a scroolbar to an item of the loc
but it seem it is necessary using "the value of".
Code: Select all
on TestThumPos
put the loc of grc "myCursor" into tLocObjet
put tLocObjet into tLoc2
put the thumbPos of scrollbar "sbSpeed" into tSpeed
add tSpeed to item 2 of tLoc2
put "tSpeed is a number =" && (tSpeed is a number) & cr & "tSpeed=" & tSpeed & cr & "tLocObjet=" & tLocObjet & cr & "tLoc2=" & tLoc2 into tResults
end TestThumPos
tSpeed is a number = true
tSpeed=2
tLocObjet=726,340
tLoc2=726,341.592538
Why and how 2 is changed to 1.592538 ?
Thanks for your lights
Best regards
Jean-Marc
Re: little confused with the thumbPos of a slider
Posted: Sat Jul 14, 2012 10:31 pm
by dunbarx
Jean-Marc.
The fact that there are six digits in the decimal portion means something. I tried this:
Code: Select all
on TestThumPos
put the loc of grc "myCursor" into tLocObjet
put tLocObjet into tLoc2
put the thumbPos of scrollbar "sbSpeed" into tSpeed
put item 2 of loc2 into temp
add tSpeed to temp
-- add tSpeed to item 2 of tLoc2
put "tSpeed is a number =" && (tSpeed is a number) & cr & "tSpeed=" & tSpeed & cr & "tLocObjet=" & tLocObjet & cr & "tLoc2=" & tLoc2 into tResults
answer tResults
end TestThumPos
Just taking item 2 of the loc and putting it into a variable fixes it for me.
If I ran this as you wrote it, with some locs of the grc, you get integers, and with others you do not. There is something in the numberFormat rearing its head here (those six default digits). I initially thought you would have to set the numberFormat to 0. Hey, have you tried this?
Craig
Re: little confused with the thumbPos of a slider
Posted: Sun Jul 15, 2012 4:21 am
by dunbarx
So I tried it. Not sure why this can possibly be pertinent, but:
Code: Select all
on TestThumPos
set the loc of grc "mycursor" to random(600) & "," & random(400)
put the loc of grc "myCursor" into tLocObjet
put tLocObjet into tLoc2
set the numberFormat to "0"
put the thumbPos of scrollbar "sbSpeed" into tSpeed
add tSpeed to item 2 of tLoc2
put "tSpeed is a number =" && (tSpeed is a number) & cr & "tSpeed=" & tSpeed & cr & "tLocObjet=" & tLocObjet & cr & "tLoc2=" & tLoc2 into tResults
answer tResults
end TestThumPos
Changes the grc loc at random and always gives clean integers. Comment the numberFormat line out, and you get six digits after the decimal point.
Craig
Re: little confused with the thumbPos of a slider
Posted: Sun Jul 15, 2012 1:18 pm
by jmburnod
Hi Craig,
Thank for reply
There is now two ways, setting the numberformat or using "the value of*
Code: Select all
put the value of the thumbPos of scrollbar "sbSpeed" into tSpeed
work also, but i think setting the numberformat is better
Best regards
Jean-Marc
Re: little confused with the thumbPos of a slider
Posted: Sun Jul 15, 2012 2:35 pm
by dunbarx
Well, good news on the solving-the-problem front.
It seems that the integrity of item 2 of the loc is not the issue, it is the thumbposition. If you:
put trunc(tSpeed) into tSpeed
the problem goes away. ThumbPositions appear to be integers. I guess they are not .
Craig
Re: little confused with the thumbPos of a slider
Posted: Sun Jul 15, 2012 3:53 pm
by jmburnod
Hi Craig,
put trunc(tSpeed) into tSpeed
Unfortunatelly not. Trunc is not a good way
If the slider is at the beginning of 4 then trunc(the thumbPos) return 3 (the value of the slider show 4)
Only ways using numberFormat or "value of" work in this case
you can experiment this with the little stack in attachment
Best
Jean-Marc
Re: little confused with the thumbPos of a slider
Posted: Sun Jul 15, 2012 5:12 pm
by LittleGreyMan
Salut Jean-Marc,
jmburnod wrote:
put trunc(tSpeed) into tSpeed
Unfortunatelly not. Trunc is not a good way
Of course: truncating takes the integer part of a number. You need to round it:
round (myNumber,0) or the round of myNumber
IMHO, more secure than using the numberFormat:
Dictionnary wrote: 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.
HTH
Re: little confused with the thumbPos of a slider
Posted: Sun Jul 15, 2012 6:13 pm
by dunbarx
Right.
I was only concerned with sanitizing the value of the thumbPosition, not suggesting any sort of working code.
My concern is rather why this should be necessary. The thumbPosition is ostensibly an integer.
But it isn't.
Craig
Re: little confused with the thumbPos of a slider
Posted: Sun Jul 15, 2012 6:15 pm
by jmburnod
Salut Didier,
Yes, round() work also but i don't like (i don't know why).
I must choose between "the value of" and "set numberformat" ways.
Best regards
Jean-Marc
Re: little confused with the thumbPos of a slider
Posted: Sun Jul 15, 2012 6:22 pm
by jmburnod
Hi Craig,
My concern is rather why this should be necessary. The thumbPosition is ostensibly an integer.
Yes. That was a surprise for me
Re: little confused with the thumbPos of a slider
Posted: Sun Jul 15, 2012 6:57 pm
by LittleGreyMan
jmburnod wrote:Hi Craig,
My concern is rather why this should be necessary. The thumbPosition is ostensibly an integer.
Yes. That was a surprise for me
Dictionnary wrote:Value:
The thumbPosition of a scrollbar is a number between the scrollbar's startValue and endValue.
No indication it's supposed to be an integer.
As stated in the User Manual, LC language is typeless, so considering thumbPosition as an integer is a pure assumption.
Re: little confused with the thumbPos of a slider
Posted: Sun Jul 15, 2012 7:21 pm
by jmburnod
Yes Didier,
You're right
put (the thumbpos of scrollbar sbSpeed is an integer) = false
Thank for light
Jean-Marc
Re: little confused with the thumbPos of a slider
Posted: Mon Jul 16, 2012 4:01 pm
by dunbarx
Just so. Live and learn.
I made a slider with an endvalue of 3. It is possible to get an integral value of the thumbPos if you push the thumb hard right or left. Hard to do in the middle.
if you:
set the numberFormat to "###.###"
answer the thumbposition of scrollbar "test" /3
you get decimal values most places along the slide. So the thumbposition returns an integer, but if you ever have to do any calculations on that value, you must know this. There may be instances where the numberFormat, round function or trunc function is appropriate. Or not; you can create a coarse slider scale, like mine above, to obtain much finer resolution if desired.
In appearance, only integers are returned. Didier is certainly correct when he says that is merely an assumption.
Craig
Re: little confused with the thumbPos of a slider
Posted: Tue Aug 14, 2012 11:08 am
by LittleGreyMan
Hi guys,
I just have been caught by this one and thought I had a smarter solution:
I noticed the inspector provides a numberFormat field for scrollbars. Having a closer look to the dictionary, I saw that LC allows to set the numberFormat of scrollBars, which is set to empty at creation.
Good.
But unfortunately, "0" doesn't seem to work. If you set it to "0.0", using the inspector or by script using the msg box, it works, the value is stored in the inspector script.
If you set it to 0, by the same ways, "answer the numberformat of scrollbar myScrollBar" returns an empty string.
Bug or feature?
Any idea?
The ability of directly setting the numberFormat would be a smarter solution than getting rid of decimals by script.
Re: little confused with the thumbPos of a slider
Posted: Tue Aug 14, 2012 2:22 pm
by dunbarx
Well, well. Yet another gadget that I never saw before.
The "Value Format" in the inspector seems to solve all display worries. If you set it to "0", you get integers. If you set it to "0.00000" you get decimals. No script required.
As for getting the numberformat property, placing a "0" in the inspector will revert to empty when you reload it. I guess "0" and empty are the same.
Try putting in "000". Reload the inspector. One "0" will go away, leaving two. The scrollbar itself will show two leading zeros, as "002, say. So if you place a single "0", it gets deleted as well, reverting back to empty.
I think it is a feature.
Craig Newman