Page 1 of 1
Keeping the scrollbar at the bottom of a field
Posted: Sun May 18, 2008 8:00 pm
by gyroscope
Hi, I have a button which adds one or more lines of type at a time to a field. When the scrollbar of the field becomes active, I would like the scrollbar slide to always appear at the bottom of the field so that the last text entry can be seen.
The only two properties which I can find which seem relevant to solving this problem are endValue and vScroll; however after experimenting with these, I am still having no luck...
So is there a neat bit of scripting that I could put into the button that would keep the scrollbar slide at the bottom, so as to always show the last text entry?
I'd appreciate any help or advice here, please!

Posted: Mon May 19, 2008 12:30 pm
by Janschenkel
Try this:
Code: Select all
on mouseUp
-- do your thing
-- now ensure itthe field scrolls to the bottom
set the vScroll of field "MyField" to the formattedHeight of field "MyField"
end mouseUp
Hope this helped,
Jan Schenkel.
Posted: Mon May 19, 2008 1:42 pm
by Mark
Dear Gyroscope,
The maximum scroll equals:
Code: Select all
the formattedHeight of fld x - the height of fld x - the margins of fld x - the textHeight of fld x
provided that the margins are an integer and the fixedLineHeight of the field is true. If the margins are no integer, you probably need to use item 4 of the margins. If the fixedLineHeight is not true, you need to find a way to figure out the height of the last line of your field. Also, the dontWrap of your field has to be set to true.
This is a nice way to do it:
Code: Select all
getProp maxScroll
if word 1 of the name of the target is "field" then
return (the formattedHeight of the target - the height of the target - the margins of the target - the textHeight of the target)
else return empty
end maxScroll
(untested, but should work)
Now, if you have this script at stack level or in a library, you can call this property using:
Code: Select all
put the maxScroll of fld x
set the vScroll of fld x to the maxScroll of fld x
The first line should return an integer, the second should set the scroll of a field to the largest possible value.
Best regards,
Mark
Posted: Mon May 19, 2008 9:31 pm
by gyroscope
Hi Jan
Thank you very much, that is perfect for my project needs at the moment, and it works a treat!
Hi Mark
Thank you also for your comprehensive coding; as it happens, I needed to be able to find out the maximum scroll of a text field for my third project so this has solved another problem I was going to post at some later time...

Posted: Mon May 19, 2008 9:36 pm
by Nonsanity
I've always just used:
Code: Select all
set the vscroll of fld x to 100000
I suppose that could fail in extreme cases, but I've never run across such a one, and I've been using this trick since the late 80's with HyperCard (less the V in vscroll).
Posted: Tue May 20, 2008 11:03 am
by gyroscope
Hi Nonsanity, thanks for the info; I did try that (with a few other figures as well) but unfortunately kept getting an error message (or it didn't seem to do anything with 100000). But if it works for you, that's good!

Posted: Tue May 20, 2008 6:55 pm
by Garrett
Or if by chance the field is acting as a list box, you can do this:
Code: Select all
set the hilitedLine of field "fList" to the number of lines of field "fList"
That would highlight the last line and cause it to scroll to the point that the last line is fully visible.
* fList being the name of field. Use whatever name your field is of course.
Posted: Tue May 20, 2008 7:01 pm
by gyroscope
I'm certain I'm going to find that useful at some point, thank you Garrett!

Keeping the scrollbar at the bottom of a field
Posted: Fri Aug 15, 2008 6:18 am
by bjb007
And set the highlight (sorry, Hilite)
color to the field background.