Speed Counters

View: New views
9 Messages — Rating Filter:   Alert me  

Speed Counters

by Michael Steinwede-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Could anyone direct me to some example or article that tells me how to  
create a speed counter.

That is, when you click on a button, the counter is incremented by 1.

If I hold the button down for, say 2 secs, the counter automatically  
increments by 1 at a faster speed until the button is released (or  
until max value is reached).

Or if the button is continually held down for, say 5 secs, the counter  
automatically increments by 1 at a very fast speed until the button is  
released (or until max value is reached).

I remember seeing an article  on this some years ago, but can't find  
it now on 4D. It could be that I searching with the wrong criteria.

Any help appreciated.

Michael

**********************************************************************
4D Basics hosted by 4D, Inc.                       http://www.4D.com/

Register for 4D Summit 2009 Today
Early Bird Pricing Ends August 28th - http://www.4D.com/summit

To Unsubscribe:                        mailto:4DBasics-off@...
**********************************************************************



Re: Speed Counters

by Douglas Davis-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I used a simple modifier (shift key) to increase the speed.  Clicking the
plus adds one item to the count.  Holding the shift and clicking adds 10 at
a time.  Sorry, don't know how to auto increase based on the length of time
held.
--
|  Douglas S. Davis - Information Systems Coordinator
|  Monical Pizza Corporation  (http://www.monicals.com)
| - - - - - - - - - -
|  815/937-1890 - Voice  .  .  .  815/937-9828 - Fax
--





**********************************************************************
4D Basics hosted by 4D, Inc.                       http://www.4D.com/

Register for 4D Summit 2009 Today
Early Bird Pricing Ends August 28th - http://www.4D.com/summit

To Unsubscribe:                        mailto:4DBasics-off@...
**********************************************************************



Parent Message unknown RE: Speed Counters

by Thomas Fitch :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Michael,

This is just pseudo-4D Code, I did not test it or run it, but the commands
you need should be correct.

Place this in the button method:
Case of
  :(form event = on clicked)
    counter:=counter+1
    SET TIMER (10)
End Case

Place this in the form method and make sure the On timer form event is
selected from the form properties:
Case of
  :(form event = on load)
    C_LONGINT(counter;tempcounter)
    counter:=0
    tempcounter:=0
  :(form event = on timer)
    GET MOUSE($x;$y;$button)
    If($button=1)
      tempcounter:=tempcounter+1
      counter:=counter+1
      case of
        :(tempcounter > 3)
          SET TIMER(8)
        :(tempcounter > 6)
          SET TIMER(6)
        :(tempcounter > 9)
          SET TIMER(4)
        :(tempcounter > 12)
          SET TIMER(2)
      End case
    Else
      SET TIMER(0)
End Case

This way when you click you increment, and you set the form timer. If you
hold the mouse button down the timer keeps running (see the GET MOUSE
command). The longer the mouse button is down (aka the more times On timer
event fires) the faster On timer fires and the faster counter gets
incremented. You can obviously play with the numbers so it works for you.

Kind Regards,

Tom Fitch
Technical Services Team Member
4D, Inc.


**********************************************************************
4D Basics hosted by 4D, Inc.                       http://www.4D.com/

Register for 4D Summit 2009 Today
Early Bird Pricing Ends August 28th - http://www.4D.com/summit

To Unsubscribe:                        mailto:4DBasics-off@...
**********************************************************************



Parent Message unknown RE: Speed Counters

by Bill Thompson-7 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I think your 'case of ' tempcounters might be in the wrong order...

-----Original Message-----
From: 4DBasics@... [mailto:4DBasics@...] On Behalf Of
Thomas Fitch
Sent: Thursday, June 04, 2009 10:47 AM
To: 4D Basics List
Subject: RE: Speed Counters

Hi Michael,

This is just pseudo-4D Code, I did not test it or run it, but the
commands
you need should be correct.

Place this in the button method:
Case of
  :(form event = on clicked)
    counter:=counter+1
    SET TIMER (10)
End Case

Place this in the form method and make sure the On timer form event is
selected from the form properties:
Case of
  :(form event = on load)
    C_LONGINT(counter;tempcounter)
    counter:=0
    tempcounter:=0
  :(form event = on timer)
    GET MOUSE($x;$y;$button)
    If($button=1)
      tempcounter:=tempcounter+1
      counter:=counter+1
      case of
        :(tempcounter > 3)
          SET TIMER(8)
        :(tempcounter > 6)
          SET TIMER(6)
        :(tempcounter > 9)
          SET TIMER(4)
        :(tempcounter > 12)
          SET TIMER(2)
      End case
    Else
      SET TIMER(0)
End Case

This way when you click you increment, and you set the form timer. If
you
hold the mouse button down the timer keeps running (see the GET MOUSE
command). The longer the mouse button is down (aka the more times On
timer
event fires) the faster On timer fires and the faster counter gets
incremented. You can obviously play with the numbers so it works for
you.

Kind Regards,

Tom Fitch
Technical Services Team Member
4D, Inc.


**********************************************************************
4D Basics hosted by 4D, Inc.                       http://www.4D.com/

Register for 4D Summit 2009 Today
Early Bird Pricing Ends August 28th - http://www.4D.com/summit

To Unsubscribe:                        mailto:4DBasics-off@...
**********************************************************************



**********************************************************************
4D Basics hosted by 4D, Inc.                       http://www.4D.com/

Register for 4D Summit 2009 Today
Early Bird Pricing Ends August 28th - http://www.4D.com/summit

To Unsubscribe:                        mailto:4DBasics-off@...
**********************************************************************



Parent Message unknown RE: Speed Counters

by Thomas Fitch :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Bill,

> I think your 'case of ' tempcounters might be in the wrong order...

You're totally right. Here's the fixed code:

Michael, here it is fixed:

Place this in the button method:
Case of
  :(form event = on clicked)
    counter:=counter+1
    SET TIMER (10)
End Case

Place this in the form method and make sure the On timer form event is
selected from the form properties:
Case of
  :(form event = on load)
    C_LONGINT(counter;tempcounter)
    counter:=0
    tempcounter:=0
  :(form event = on timer)
    GET MOUSE($x;$y;$button)
    If($button=1)
      tempcounter:=tempcounter+1
      counter:=counter+1
      case of
        :(tempcounter > 12)
          SET TIMER(2)
        :(tempcounter > 9)
          SET TIMER(4)
        :(tempcounter > 6)
          SET TIMER(6)
        :(tempcounter > 3)
          SET TIMER(8)
      End case
    Else
      SET TIMER(0)
End Case

Kind Regards,

Tom Fitch
Technical Services Team Member
4D, Inc.

**********************************************************************
4D Basics hosted by 4D, Inc.                       http://www.4D.com/

Register for 4D Summit 2009 Today
Early Bird Pricing Ends August 28th - http://www.4D.com/summit

To Unsubscribe:                        mailto:4DBasics-off@...
**********************************************************************



Re: Speed Counters

by Michael Steinwede-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Douglas,

Interestingly, I have another software application program that does  
almost the same thing to jump by 10 (that is, hold down the shift key  
while clicking a button), but it never occurred to me to try in my  
database.

It's not what I'm wanting in my particular case, but worth keeping in  
mind for another time.

Many thanks,

Michael.


On 04/06/2009, at 10:59 PM, Douglas Davis wrote:

> I used a simple modifier (shift key) to increase the speed.  
> Clicking the
> plus adds one item to the count.  Holding the shift and clicking  
> adds 10 at
> a time.  Sorry, don't know how to auto increase based on the length  
> of time
> held.


**********************************************************************
4D Basics hosted by 4D, Inc.                       http://www.4D.com/

Register for 4D Summit 2009 Today
Early Bird Pricing Ends August 28th - http://www.4D.com/summit

To Unsubscribe:                        mailto:4DBasics-off@...
**********************************************************************



Re: Speed Counters

by Michael Steinwede-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Tom,

Well, I did what you've suggested below, made sure the ON TIMER event  
on the form is selected, but nothing.

Well, not quite. It increments and decrements OK as before, but no  
speed counting takes place.

I have two issues, however.

(1) When I put a trace on to see what was happening, I noticed that in  
the object method, the hb_UpTime is set to 1 (which you would expect),  
but when the routine jumps to On Timer, the button hb_UpTime was reset  
to 0. So the large part of the On Timer routine is never activated.
(I'm not concerned with the other button, hb_DownTime - see code below  
- as I'm just trying to see how one button works and once I know that,  
I can set up the other buttons appropriately with various tests to  
ensure the On Timer event works for the button activated. I have eight  
buttons in all on the form that I want to use the speed counter.)

(2) Why do we have an increment counter in the Object method AND in  
the Form method in the On Timer event?

Many thanks for your comments.

Michael

Here's my code for the Form Method

        : (Form event=On Load )
                C_LONGINT(tempcounter)
                C_LONGINT($x;$y; vn_CareTime)
                tempcounter:=0
                vn_CareTime:=0
               
        : (Form event=On Timer )
                GET MOUSE($x;$y;hb_UpTime)
                If (hb_UpTime=1)
                        tempcounter:=tempcounter+1
                        vn_CareTime:=vn_CareTime+1
                        Case of
                                : (tempcounter>12)
                                        SET TIMER(2)
                                : (tempcounter>9)
                                        SET TIMER(4)
                                : (tempcounter>6)
                                        SET TIMER(6)
                                : (tempcounter>3)
                                        SET TIMER(8)
                        End case
                Else
                        SET TIMER(0)
                End if

And here's my code for the Object Method of my button (hb_UpTime)

        : (Form event=On Clicked )
                vn_CareTime:=vn_CareTime+1
                SET TIMER(10)
                If (vn_CareTime=200)
                        DISABLE BUTTON(hb_UpTime)
                Else
                        ENABLE BUTTON(hb_DownTime)
                End if


**********************************************************************
4D Basics hosted by 4D, Inc.                       http://www.4D.com/

Register for 4D Summit 2009 Today
Early Bird Pricing Ends August 28th - http://www.4D.com/summit

To Unsubscribe:                        mailto:4DBasics-off@...
**********************************************************************



Parent Message unknown RE: Speed Counters

by Thomas Fitch :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Michael,

I tested the code and you're correct. It doesn't work. The problem is that I
tried to port over a picture variable object solution to a button object and
the On Clicked form event works differently for the button object. It
doesn't fire until after the mouse button comes up, so you never have
hb_UpTime=1 in your On Timer code.

The method I suggested isn't going to work with a button. I do have another
suggestion though... use a picture variable. :-)

I outline it in this tech tip:

http://kb.4d.com/search/assetid=75706

The tech tip discusses how to implement drag and drop in SVG images but you
can use the same idea to implement a speed counter. Use the Mouse Enter,
Mouse Leave, and On Clicked events of the picture variable to manage the
Timer and then handle the incrementing via the On Time form event.

Sorry for the confusion.

Kind Regards,

Tom Fitch
Technical Services Team Member
4D, Inc.


**********************************************************************
4D Basics hosted by 4D, Inc.                       http://www.4D.com/

Register for 4D Summit 2009 Today
Early Bird Pricing Ends August 28th - http://www.4D.com/summit

To Unsubscribe:                        mailto:4DBasics-off@...
**********************************************************************



Re: Speed Counters

by Michael Steinwede-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Tom,

On 06/06/2009, at 2:18 AM, Thomas Fitch wrote:

> The method I suggested isn't going to work with a button. I do have  
> another
> suggestion though... use a picture variable. :-)
>
>
> I outline it in this tech tip:
>
> http://kb.4d.com/search/assetid=75706
>
> The tech tip discusses how to implement drag and drop in SVG images  
> but you
> can use the same idea to implement a speed counter. Use the Mouse  
> Enter,
> Mouse Leave, and On Clicked events of the picture variable to manage  
> the
> Timer and then handle the incrementing via the On Time form event.

I couldn't get your second suggestion to work either.

However, looking up Form events I came across this ...

For all these objects, the On Clicked event occurs once the mouse  
button is released. However, there are several exceptions:
• Invisible buttons - The On Clicked event occurs as soon as the click  
is made and does not wait for the mouse button to be released.

Remembering your earlier comments, I tried invisible buttons and with  
a few adjustments, I was able to get it to work!

Thanks for your input and suggestions, it gave me all the clues I  
needed and learnt heaps.

Michael.

PS. Here's the code I used.

Invisible button Object Method code ...

        : (Form event=On Clicked )
                UserButtonDown:=True
                SET TIMER(10)
                If (vn_CareTime=20)
                        DISABLE BUTTON(bi_UpTime)
                        SET TIMER(0)
                Else
                        vn_CareTime:=vn_CareTime+0.25
                        ENABLE BUTTON(bi_DownTime)
                End if


Form Method Code ...

        : (Form event=On Load )
                C_LONGINT(iCnt)
                C_LONGINT($x;$y;$MouseState)  `// not used, but needed for On Timer  
event below
                C_BOOLEAN(UserButtonDown)
                UserButtonDown:=False
                iCnt:=0

        : (Form event=On Timer )
                GET MOUSE($x;$y;$MouseState)  `// get mouse state
                If (($MouseState=1) & (UserButtonDown))  `// 1 = mouse button down
                        If (vn_CareTime=20)
                                SET TIMER(0)
                                UserButtonDown:=False
                                iCnt:=0
                        Else
                                iCnt:=iCnt+1
                                vn_CareTime:=vn_CareTime+0.25
                                Case of
                                        : (iCnt>20)  `// go very fast
                                                SET TIMER(2)
                                        : (iCnt>5)  `// go faster
                                                SET TIMER(15)
                                        : (iCnt<5)  `// go slowly
                                                SET TIMER(25)
                                End case
                        End if
                Else
                        SET TIMER(0)
                        UserButtonDown:=False
                        iCnt:=0
                End if
               





**********************************************************************
4D Basics hosted by 4D, Inc.                       http://www.4D.com/

Register for 4D Summit 2009 Today
Early Bird Pricing Ends August 28th - http://www.4D.com/summit

To Unsubscribe:                        mailto:4DBasics-off@...
**********************************************************************