Increment number in textbox with KeyDown
On Feb 23, 5:08*am, Bob Bridges
wrote:
Seems to me if you want to keep sHours from going negative, you just need to
include a statement to keep it from going negative:
* If IsNumeric(sHours) Then
* * sHours = sHours + v * 0.25
* * If sHours < 0 then sHours = 0
* * txtHours01 = Format(sHours, "#0.00")
* * End If
--- "Slim Slender" wrote:
How can I prevent this from 'going negative'....It should be able
to decrement in case it is taken to high, but for my present
purposes negative numbers are not acceptable.
Private Sub txtHours01_KeyDown(ByVal KeyCode _
* As MSForms.ReturnInteger, ByVal Shift As Integer)
* Dim sHours As String, v As Integer
* Select Case KeyCode
* * Case 37: v = -1 'left
* * Case 39: v = 1 'right
* * Case Else: v = 0
* * End Select
* sHours = txtHours01.Text
* If IsNumeric(sHours) And v < 0 Then
* * sHours = sHours + v * 0.25
* * txtHours01 = Format(sHours, "#0.00")
* * End If
* End Sub- Hide quoted text -
- Show quoted text -
Thanks Bob, that did the job.
|