How can I know the button is pressed?

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2007
Posts: 95
Reputation: zawpai is an unknown quantity at this point 
Solved Threads: 0
zawpai zawpai is offline Offline
Junior Poster in Training

How can I know the button is pressed?

 
0
  #1
Jan 13th, 2009
Hi,
Could anyone give me some suggestion?
How can I detect the button is pressed continuously? Actually, I use Command1_MouseDown , but it is not succeed.

I would like to do the application continuously if the button is pressed. If the user release (mouse up), I will stop the application.

How should I do?

Best regards,
zawpai
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 24
Reputation: kain_mcbride is an unknown quantity at this point 
Solved Threads: 3
kain_mcbride's Avatar
kain_mcbride kain_mcbride is offline Offline
Newbie Poster

Re: How can I know the button is pressed?

 
1
  #2
Jan 13th, 2009
when you say running the application continuously, i'm assuming you mean there's looping going on?

alright... well, there are a few ways you could do it... easiest way might be defining a boolean variable... for instance
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. option explicit
  2. private bRunning as boolean
then you can set the variable and run whatever you're running with the mouse down event...
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  2. 'set the variable
  3. bRunning = true
  4. 'run the program
  5. call doLoopedStuff
  6. end sub
then with the mouse up event you terminate it
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  2. bRunning = false
  3. end sub
all this is nice and all, but won't really help much if your program is looping intencely and doesnt' pay attention to the events... so be sure to DoEvents
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. private sub doLoopedStuff()
  2. do while(bRunning=true)
  3. doEvents
  4. 'your code stuff
  5. loop
  6. end sub
Last edited by kain_mcbride; Jan 13th, 2009 at 5:15 am. Reason: adding stuff? :p
... there is no bug that enough coffee cannot fix...
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 95
Reputation: zawpai is an unknown quantity at this point 
Solved Threads: 0
zawpai zawpai is offline Offline
Junior Poster in Training

Re: How can I know the button is pressed?

 
0
  #3
Jan 13th, 2009
Hello kain_mcbride,

Thank you for your information.

I confuse MouseDown and KeyPress . So, I posted it. You know it is doing the looping automatically if we use Form_KeyDown and press any key.

So, I want to make sure them clearly. Can I ask you one more question? What the difference between MouseDown and Click ?

Best regards,
zawpai
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 95
Reputation: zawpai is an unknown quantity at this point 
Solved Threads: 0
zawpai zawpai is offline Offline
Junior Poster in Training

Re: How can I know the button is pressed?

 
0
  #4
Jan 13th, 2009
hi kain_mcbride,

I have tried the method you gave me. It is working well, but

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. private sub doLoopedStuff()
  2. do while(bRunning=true)
  3. doEvents
  4. 'your code stuff
  5. loop
  6. end sub

have one problem. If we change it to

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. private sub doLoopedStuff()
  2. do while(bRunning=true)
  3. 'your code stuff
  4. doEvents
  5. loop
  6. end sub

You know, after doing doEvents , our program should Exit Do .

Thank a lot.
zawpai
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 24
Reputation: kain_mcbride is an unknown quantity at this point 
Solved Threads: 3
kain_mcbride's Avatar
kain_mcbride kain_mcbride is offline Offline
Newbie Poster

Re: How can I know the button is pressed?

 
0
  #5
Jan 13th, 2009
Originally Posted by zawpai View Post
Can I ask you one more question? What the difference between MouseDown and Click ?
MouseDown is when you push the mouse button down... it's not a full click, just when you press the button...

Click is a full click... mouse down / mouse up in close succession over the same object / location...

typicly click would be used... just detects if the user has clicked something in a normal kind of way... however, i understood your specifications to say that the program would run continually until the button was released... so, mouse down fires where as click won't... then you can use mouse up later to break the loop
... there is no bug that enough coffee cannot fix...
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 24
Reputation: kain_mcbride is an unknown quantity at this point 
Solved Threads: 3
kain_mcbride's Avatar
kain_mcbride kain_mcbride is offline Offline
Newbie Poster

Re: How can I know the button is pressed?

 
0
  #6
Jan 14th, 2009
Originally Posted by zawpai View Post
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. private sub doLoopedStuff()
  2. do while(bRunning=true)
  3. 'your code stuff
  4. doEvents
  5. loop
  6. end sub

You know, after doing doEvents , our program should Exit Do .

Thank a lot.
zawpai
hello zawpai

I don't fully understand, and may have misunderstood your initial problem. You were having problems with the MouseDown event, which you were trying to use to cause your program to run continually until the button was released. I assumed that you meant that you had a section of code that you wanted to run repeatedly while the button was held down.

As such, i put it in a do while loop, with the clause that bRunning had to be true for the loop to continue... DoEvents prevents the program from taking full priority in the loop, causing the events that should be firing to fire vs waiting in the loop for whatever clause or justification that needs to be met to be met...

Anyway, i'm not really sure what you mean now.
... there is no bug that enough coffee cannot fix...
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 95
Reputation: zawpai is an unknown quantity at this point 
Solved Threads: 0
zawpai zawpai is offline Offline
Junior Poster in Training

Re: How can I know the button is pressed?

 
0
  #7
Jan 14th, 2009
Hello kain_mcbride,

MouseDown is when you push the mouse button down... it's not a full click, just when you press the button...

Click is a full click... mouse down / mouse up in close succession over the same object / location...

Thank you for your good explanation. Now, I am clear about it.

(Toggle Plain Text)

private sub doLoopedStuff()
 do while(bRunning=true)
  'your code stuff
  doEvents
 loop
end sub

You know, after doing doEvents , our program should Exit Do .

Sorry for above case, I didn't mean you are wrong. You are right.
Because of my application, I just change the sequence.

Thank you for your helping.

zawpai
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2,641
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Solved Threads: 245
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

Re: How can I know the button is pressed?

 
0
  #8
Jan 15th, 2009
using ascii checking on your button event.
Last edited by Jx_Man; Jan 15th, 2009 at 10:31 pm.
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 1172 | Replies: 7
Thread Tools Search this Thread



Tag cloud for Visual Basic 4 / 5 / 6
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC