Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Limit input in a textbox

Hello NG,
I need to limit the input in a text box via the Key_Press event in VBA.
I'm accepting input for hexadecimal to be converted to Decimal and Binary
but I only the user to be able to input 0-9,a-f and A-F.
I can get a limit with using
If KeyAscii <48 OR KeyAscii 57 then KeyAscii = 0
This works but only for one set, either numbers or small letter or Caps, but
not all.
Does anyone know how to make a set of character to use, something like
(0123456789abcdefABCDEF)
Any help would be greatly appreciated.
Thanks
Jim


  #2   Report Post  
Posted to microsoft.public.excel.programming
acw acw is offline
external usenet poster
 
Posts: 19
Default Limit input in a textbox

Jim

Try
Private Sub TextBox1_KeyPress(ByVal KeyAscii As
MSForms.ReturnInteger)
Select Case KeyAscii
Case 48 To 57, 65 To 70, 97 To 102

Case Else
KeyAscii = 0
End Select

End Sub


Tony
-----Original Message-----
Hello NG,
I need to limit the input in a text box via the Key_Press

event in VBA.
I'm accepting input for hexadecimal to be converted to

Decimal and Binary
but I only the user to be able to input 0-9,a-f and A-F.
I can get a limit with using
If KeyAscii <48 OR KeyAscii 57 then KeyAscii = 0
This works but only for one set, either numbers or small

letter or Caps, but
not all.
Does anyone know how to make a set of character to use,

something like
(0123456789abcdefABCDEF)
Any help would be greatly appreciated.
Thanks
Jim


.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Limit input in a textbox

ACW and Robin,
Thanks for the tips, I got it to work with the CASE version, but I have
another text box that the InStr ver will work with better.
Thanks again, you saved me a big headache ;-)

Jim
"Robin Hammond" wrote in message
...
If you have the rest of the code working, something like this should do it

If InStr("0123456789abcdefABCDEF", Chr(keyascii)) 0 Then
MsgBox "valid character found"
End If

--
Robin Hammond
www.enhanceddatasystems.com
Check out our XspandXL add-in


"James Agostinho" wrote in message
ink.net...
Hello NG,
I need to limit the input in a text box via the Key_Press event in VBA.
I'm accepting input for hexadecimal to be converted to Decimal and

Binary
but I only the user to be able to input 0-9,a-f and A-F.
I can get a limit with using
If KeyAscii <48 OR KeyAscii 57 then KeyAscii = 0
This works but only for one set, either numbers or small letter or Caps,

but
not all.
Does anyone know how to make a set of character to use, something like
(0123456789abcdefABCDEF)
Any help would be greatly appreciated.
Thanks
Jim






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
show the input message of a data validation list on a textbox and set editable HCS7 Excel Discussion (Misc queries) 3 November 20th 08 11:43 AM
Character limit in textbox Ashley Excel Worksheet Functions 1 September 10th 08 01:33 AM
excel input mask for textbox DaveF[_2_] Excel Discussion (Misc queries) 3 February 20th 08 03:25 PM
Validy check in one coulmn to limit input options in another? Katja Excel Worksheet Functions 2 January 5th 06 06:53 PM
Limit character input Mike[_37_] Excel Programming 2 August 13th 03 08:18 PM


All times are GMT +1. The time now is 04:30 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"