| | |
How can I know the button is pressed?
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2007
Posts: 95
Reputation:
Solved Threads: 0
Hi,
Could anyone give me some suggestion?
How can I detect the button is pressed continuously? Actually, I use
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
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
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
then you can set the variable and run whatever you're running with the mouse down event...
then with the mouse up event you terminate it
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
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)
option explicit private bRunning as boolean
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) 'set the variable bRunning = true 'run the program call doLoopedStuff end sub
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) bRunning = false end sub
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
private sub doLoopedStuff() do while(bRunning=true) doEvents 'your code stuff loop 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...
•
•
Join Date: Oct 2007
Posts: 95
Reputation:
Solved Threads: 0
Hello kain_mcbride,
Thank you for your information.
I confuse
So, I want to make sure them clearly. Can I ask you one more question? What the difference between
Best regards,
zawpai
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
•
•
Join Date: Oct 2007
Posts: 95
Reputation:
Solved Threads: 0
hi kain_mcbride,
I have tried the method you gave me. It is working well, but
have one problem. If we change it to
You know, after doing
Thank a lot.
zawpai
I have tried the method you gave me. It is working well, but
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
private sub doLoopedStuff() do while(bRunning=true) doEvents 'your code stuff loop end sub
have one problem. If we change it to
Visual Basic 4 / 5 / 6 Syntax (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 .Thank a lot.
zawpai
•
•
•
•
Can I ask you one more question? What the difference betweenMouseDownandClick?
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...
•
•
•
•
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
private sub doLoopedStuff() do while(bRunning=true) 'your code stuff doEvents loop end sub
You know, after doingdoEvents, our program shouldExit Do.
Thank a lot.
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...
•
•
Join Date: Oct 2007
Posts: 95
Reputation:
Solved Threads: 0
Hello kain_mcbride,
Thank you for your good explanation. Now, I am clear about it.
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
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
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 *
So, Please do something before post your thread.
* PM Asking will be ignored *
![]() |
Similar Threads
- Problem changing contents of JTable when button is pressed... (Java)
- How to determine which button was pressed? (JavaScript / DHTML / AJAX)
- stopping code executing if cancel button pressed on msgbox (VB.NET)
- How to open a dialogue box and loads a file, when button is pressed in ms-access (Visual Basic 4 / 5 / 6)
- URGENT!: Saving Database information from ASP.NET Button (ASP.NET)
- Gettig delphi to wait for a button press before continuing (Pascal and Delphi)
- Recognizing when a button is pressed. (Java)
- Help in printing mulitple documents using print button (Java)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Search for Exact Phrase in String using VBA
- Next Thread: Copying Tables From Word and Pasting in Excel in VBA
Views: 1172 | Replies: 7
| Thread Tools | Search this Thread |
Tag cloud for Visual Basic 4 / 5 / 6
* 6 429 2007 access activex add age append application basic beginner birth bmp c++ calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh report retrieve save search sendbyte sites sort sql sql2008 sqlserver struct subroutine table tags textbox time timer urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows






