Solved

Relatively Simple Question: MouseDown event handling

Posted on 2002-03-28
6
299 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
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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

839 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