Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Relatively Simple Question: MouseDown event handling

Posted on 2002-03-28
6
Medium Priority
?
305 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 200 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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 While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

604 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