Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Increment number in textbox with KeyDown

Okay, let's try this.
How can I prevent this from 'going negative' like a campaigning
politician.
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
Dim v As Integer

Select Case KeyCode
Case 37 ' Left
v = -1
Case 39 ' Right
v = 1
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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 257
Default Increment number in textbox with KeyDown

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default 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.
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
KeyDown in TextBox to increment Number Slim Slender[_2_] Excel Programming 0 February 22nd 10 12:32 AM
Increment number on command Tom Ogilvy Excel Programming 0 January 9th 07 12:58 AM
increment version number Lozza77 Excel Discussion (Misc queries) 4 May 17th 06 09:17 AM
Textbox Keydown event not triggered. droopy928gt[_15_] Excel Programming 0 May 8th 06 02:52 PM
Increment number by 1 Joe Derr Excel Programming 5 May 16th 04 08:28 PM


All times are GMT +1. The time now is 11:57 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"