Solved

Relatively Simple Question: MouseDown event handling

Posted on 2002-03-28
6
301 Views
Last Modified: 2010-05-02
I am handling a mousedown event on a button. I want to execute a line of code, say, increase some integer's value by one, as long as the mouse is down on the button.

What i see is, if don't use a loop, the code is executed only once.

The other method i tried was:

1. declared a global variable,

2. execute that one statement in the loop in mousedown event's method as long as the global variable's value doesn't change..

3. change the value of global variable in mouseup ( or  mousereleased ) event.

But the loop in mousedown event never breaks even after the mouse is released.

Any suggestions? I just want to repeatedly do something as long as the mouse is pressed on the button.




0
Comment
Question by:maggari
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 50 total points
ID: 6903452
try adding a timer,  set the Timer interval to 1000 (One second), then in the MouseDown event, enable the timer.  In the Timer event (which will then go off every second), increment the Integer variable (probably make it at least a Form_Level variable).  Then in the Button's MouseUP event, turn the Timer off again.

Is that what you have in mind?

Arthur Wood
0
 

Author Comment

by:maggari
ID: 6903652
Thanks for your reply.. but timer is the last option i would resort to.. the interval for the timer itself becomes a major issue in my case.. i am working with a socket based application which communicates over a network.. and therefore don't wanna do it with a timer..
is that the only way?
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6903831
I don't see that you really have an option.

Since everything is event-driven, what you get is events triggering things.  What event do you want to occur when the mouse is down?  If you simply start a counter, how frequently should the counter increment--as fast as the processor or communication can go, or whenever it gets a message (and event!)?

Most likely, you want the counter to occur at certain interval, which means that you need a timer of some sort.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 6903907
clarify ".. the interval for the timer itself becomes a major issue in my case"  what do you mean by that?

Maybe you should clrify exactly what you are trying to accomplish with the Mouse Down, on a Button?
0
 
LVL 6

Expert Comment

by:DrDelphi
ID: 6904438
Just off the top of my head....



Dim go As Boolean
Dim MouseCount As Long


Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
go = True 'allow looping to begin
While go
  MouseCount = MouseCount + 1
  DoEvents 'allow messages to be processed
Wend
End Sub

Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
go = False 'shut down the looping
MsgBox MouseCount
End Sub




Good luck!!
0
 

Author Comment

by:maggari
ID: 6904483
I solved my problem. I used the timer though. Didn't find any alternative. Thank you for your help fellas. Arthur wood gets the points.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question