Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to create a check to allow user to input numerics from the numeric pad
Private Sub txtZip_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer) ' Pass through only digits. If KeyCode < 48 Or KeyCode 57 Then KeyCode = 0 Beep End If ' As I found out the numerics from the numeric pad range from 0x60 to 0x69 ' Could someone show me how to set up a valid check for them ? If KeyCode < "0x60" Or KeyCode "0x69" Then KeyCode = 0 Beep End If End Sub |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to create a check to allow user to input numerics from the num
Put in a userform with Textbox1 and Label1
Put in code like this: Private Sub TextBox1_Change() TextBox1.Value = "" End Sub Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) Label1.Caption = KeyCode End Sub now test the keys - with numlock on and off. Also look at other keys on the keyboard. Use a select case statement to sort them out. -- Regards, Tom Ogilvy " wrote: Private Sub txtZip_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, _ ByVal Shift As Integer) ' Pass through only digits. If KeyCode < 48 Or KeyCode 57 Then KeyCode = 0 Beep End If ' As I found out the numerics from the numeric pad range from 0x60 to 0x69 ' Could someone show me how to set up a valid check for them ? If KeyCode < "0x60" Or KeyCode "0x69" Then KeyCode = 0 Beep End If End Sub |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to create a check to allow user to input numerics from the num
Just wondering... what's the best way to do a backspace ?
I figure the KeyCode = 8 for backspace. Tom Ogilvy wrote: Put in a userform with Textbox1 and Label1 Put in code like this: Private Sub TextBox1_Change() TextBox1.Value = "" End Sub Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) Label1.Caption = KeyCode End Sub now test the keys - with numlock on and off. Also look at other keys on the keyboard. Use a select case statement to sort them out. -- Regards, Tom Ogilvy " wrote: Private Sub txtZip_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, _ ByVal Shift As Integer) ' Pass through only digits. If KeyCode < 48 Or KeyCode 57 Then KeyCode = 0 Beep End If ' As I found out the numerics from the numeric pad range from 0x60 to 0x69 ' Could someone show me how to set up a valid check for them ? If KeyCode < "0x60" Or KeyCode "0x69" Then KeyCode = 0 Beep End If End Sub |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to create a check to allow user to input numerics from the num
Yes, 8 is a backspace.
-- Regards, Tom Ogilvy wrote in message oups.com... Just wondering... what's the best way to do a backspace ? I figure the KeyCode = 8 for backspace. Tom Ogilvy wrote: Put in a userform with Textbox1 and Label1 Put in code like this: Private Sub TextBox1_Change() TextBox1.Value = "" End Sub Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) Label1.Caption = KeyCode End Sub now test the keys - with numlock on and off. Also look at other keys on the keyboard. Use a select case statement to sort them out. -- Regards, Tom Ogilvy " wrote: Private Sub txtZip_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, _ ByVal Shift As Integer) ' Pass through only digits. If KeyCode < 48 Or KeyCode 57 Then KeyCode = 0 Beep End If ' As I found out the numerics from the numeric pad range from 0x60 to 0x69 ' Could someone show me how to set up a valid check for them ? If KeyCode < "0x60" Or KeyCode "0x69" Then KeyCode = 0 Beep End If End Sub |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to create a check to allow user to input numerics from the num
I understand it's 8. But what I am interested in is how to manipulate
the display such that pressing an 8 would actually be displaying an erase. In a sense, I would like to see if there's any way to do the same thing as SUBSTR (str , 1, length(str) -1) Thanks, -DP Tom Ogilvy wrote: Yes, 8 is a backspace. -- Regards, Tom Ogilvy wrote in message oups.com... Just wondering... what's the best way to do a backspace ? I figure the KeyCode = 8 for backspace. Tom Ogilvy wrote: Put in a userform with Textbox1 and Label1 Put in code like this: Private Sub TextBox1_Change() TextBox1.Value = "" End Sub Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) Label1.Caption = KeyCode End Sub now test the keys - with numlock on and off. Also look at other keys on the keyboard. Use a select case statement to sort them out. -- Regards, Tom Ogilvy " wrote: Private Sub txtZip_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, _ ByVal Shift As Integer) ' Pass through only digits. If KeyCode < 48 Or KeyCode 57 Then KeyCode = 0 Beep End If ' As I found out the numerics from the numeric pad range from 0x60 to 0x69 ' Could someone show me how to set up a valid check for them ? If KeyCode < "0x60" Or KeyCode "0x69" Then KeyCode = 0 Beep End If End Sub |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to create a check to allow user to input numerics from the num
Textbox.Text = Left(Textbox.Text,len(Textbox.Text)-1)
or Textbox.Text = Mid(Textbox.Text,1,len(Textbox.Text)-1) -- Regards, Tom Ogilvy wrote in message ups.com... I understand it's 8. But what I am interested in is how to manipulate the display such that pressing an 8 would actually be displaying an erase. In a sense, I would like to see if there's any way to do the same thing as SUBSTR (str , 1, length(str) -1) Thanks, -DP Tom Ogilvy wrote: Yes, 8 is a backspace. -- Regards, Tom Ogilvy wrote in message oups.com... Just wondering... what's the best way to do a backspace ? I figure the KeyCode = 8 for backspace. Tom Ogilvy wrote: Put in a userform with Textbox1 and Label1 Put in code like this: Private Sub TextBox1_Change() TextBox1.Value = "" End Sub Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) Label1.Caption = KeyCode End Sub now test the keys - with numlock on and off. Also look at other keys on the keyboard. Use a select case statement to sort them out. -- Regards, Tom Ogilvy " wrote: Private Sub txtZip_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, _ ByVal Shift As Integer) ' Pass through only digits. If KeyCode < 48 Or KeyCode 57 Then KeyCode = 0 Beep End If ' As I found out the numerics from the numeric pad range from 0x60 to 0x69 ' Could someone show me how to set up a valid check for them ? If KeyCode < "0x60" Or KeyCode "0x69" Then KeyCode = 0 Beep End If End Sub |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to create a check to allow user to input numerics from the num
Thanks, it works. But I figure there's a defect to it. It basically
removes 2 numerics a time. Maybe it treats it as a 32-bit word when it performs len(txt) = len(txt) -1 . Please advice. Here is my code. Private Sub txtZip_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, _ ByVal Shift As Integer) ' Pass through only digits. ' Backspace is enabled ' Numerics keyed in thru' num pad is enabled If KeyCode = 8 Then If Len(txtZip.Text) 0 Then txtZip.Text = Left(txtZip.Text, Len(txtZip.Text) - 1) End If Else If KeyCode < 48 Then KeyCode = 0 Beep Else If KeyCode <= 57 Or (KeyCode = 96 And KeyCode <= 105) Then Else KeyCode = 0 Beep End If End If End If End Sub Tom Ogilvy wrote: Textbox.Text = Left(Textbox.Text,len(Textbox.Text)-1) or Textbox.Text = Mid(Textbox.Text,1,len(Textbox.Text)-1) -- Regards, Tom Ogilvy wrote in message ups.com... I understand it's 8. But what I am interested in is how to manipulate the display such that pressing an 8 would actually be displaying an erase. In a sense, I would like to see if there's any way to do the same thing as SUBSTR (str , 1, length(str) -1) Thanks, -DP Tom Ogilvy wrote: Yes, 8 is a backspace. -- Regards, Tom Ogilvy wrote in message oups.com... Just wondering... what's the best way to do a backspace ? I figure the KeyCode = 8 for backspace. Tom Ogilvy wrote: Put in a userform with Textbox1 and Label1 Put in code like this: Private Sub TextBox1_Change() TextBox1.Value = "" End Sub Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) Label1.Caption = KeyCode End Sub now test the keys - with numlock on and off. Also look at other keys on the keyboard. Use a select case statement to sort them out. -- Regards, Tom Ogilvy " wrote: Private Sub txtZip_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, _ ByVal Shift As Integer) ' Pass through only digits. If KeyCode < 48 Or KeyCode 57 Then KeyCode = 0 Beep End If ' As I found out the numerics from the numeric pad range from 0x60 to 0x69 ' Could someone show me how to set up a valid check for them ? If KeyCode < "0x60" Or KeyCode "0x69" Then KeyCode = 0 Beep End If End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Create a user input query so it can be added on the switchboard? | Excel Discussion (Misc queries) | |||
Check user input | Excel Programming | |||
check is input textboxes is numeric on userform | Excel Programming | |||
Check a user-input value against a list of values? | Excel Programming | |||
create a user input form | Excel Programming |