Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Make number in text-box increase continuously responds to a KeyPress

Status
Not open for further replies.

softlover

Programmer
Apr 4, 2002
88
CN
In a form I need the number in a text-box increase/decrease it's value continuously when the Command1 or the Command2 button are pressed.
I had try the Command1_MouseDown event but the number can change after every mouse-click. I had to click and click to increase/decrease the number. Below is the codes.
Private Sub Command1_MouseDown(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
If Me.text1.Value < 200 Then
Me.text1.Value = Me.text1.Value + 1
End If
End Sub
I need the number change continuously after one press.
 
Create a label on the form (called label6 in this code)

Add this code to the forms timer event.

Private Sub Form_Timer()
If Label6.Caption = 1 Then
text1.Value = text1.Value + 1
End If
If Label6.Caption = 2 Then
text1.Value = text1.Value - 1
End If
End sub

And add this to the onclick events of each command button

Private Sub Command1_Click()
Label6.Caption = 1
End Sub

Private Sub Command2_Click()
Label6.Caption = 2
End Sub
 
also set the timer interval of the form to something suitable like 1000
 
Thanks to jaydeebetoo,
But now the increase or decrease can't STOP until close the form. Maybe need another command button [STOP] to set the Label6.Caption to "0" to stop the event.
But I don't like more command button on the form.
I only need: click and Press the Command1, the number will increase continuously until release the Left-key of mouse.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top