Scrollbardrag drag

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:

Scrollbardrag drag

Post by hamlynart » Wed Aug 05, 2009 11:24 pm

Hi,

I'm a bit confused - why doesn't this work:

Code: Select all

on scrollbarDrag
   if myVariable <=1 then
      add 1 to fld "myField"
      put 1 into myVariable
   end if
   put the thumbPosition of me into fld "Data"
end scrollbarDrag
Basically I'd like to use the "if" statement to execute a command just once at the beginning of the scrollbardrag but to continue with other stuff.

Any thoughts much appreciated.

Jim H

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

Post by bn » Thu Aug 06, 2009 12:03 am

Jim,

myVariable is not initialised and it does not persist. So nothing is in myVariable that could trigger your if structure (<=). In your script myVariable = "myVariable"

you can see this if you change your code to

Code: Select all

if myVariable = "myVariable" then
but
since scrollbardrag is send repeatedly you will get many calls to your if structure. Just put it into a mousedown handler which is invoked at the click on the scrollbar once.
If I understand you correctly something like

Code: Select all

on scrollbarDrag
    put the thumbposition of me into fld "Data"
end scrollbarDrag

on mouseDown
        add 1 to field "myField"
end mouseDown
should do what you want. It counts how many times the scrollbar was clicked and gives you continously the thumbposition. (provided field "myField" was initialised to 0)

regards
Bernd

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

Post by hamlynart » Thu Aug 06, 2009 12:21 am

Bernd,

Wow - that works perfectly! I've been struggling with this for hours. You're right, it was the repeating that was causing the problem.

Many Thanks

Jim H

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Post by Klaus » Thu Aug 06, 2009 8:36 am

Hi Jim,

hint:
The "scrollbardrag" message will also have a parameter that you can use:

Code: Select all

on scrollbardrag tValue 
## this will be the current real-time value of the scrollbar = thumbpos)
  put tValue into fld "Data"
end scrollbardrag
This is a tiny bit more efficient than additionally querying the thumbposition in the handler :)


Best

Klaus

Post Reply