Solved

Relatively Simple Question: MouseDown event handling

Posted on 2002-03-28
6
294 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now