473,569 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

keypressed

vb.net 2003
i have the following procedure

Private Sub StrLicence_KeyP ress(ByVal sender As Object, ByVal e As
System.Windows. Forms.KeyPressE ventArgs) Handles StrLicence.KeyP ress
Select Case e.KeyChar
Case Microsoft.Visua lBasic.ChrW(13)
MsgBox(" ENTER PRESSED")
' move to next field
Case Microsoft.Visua lBasic.ChrW(8)
MsgBox(" backspace PRESSED")
Case Microsoft.Visua lBasic.ChrW(9)
MsgBox("TAB PRESSED")
' move to next field
Case Microsoft.Visua lBasic.ChrW(48) To
Microsoft.Visua lBasic.ChrW(57)
MsgBox(" NUMBER PRESSED")
Case Else
' show error
MsgBox("MUST BE NUMERIC")
End Select
End Sub

what i want to do is in this case if an alpha charachter is pressed, i show
the must be numeric message, but i also want to stop that character being
displayed ...
Sep 28 '06 #1
2 4907
The procedure I use I've updated from a VB function for KeyAscii.

Here is an example of the call.

Private Sub txtQtyShipped_K eyPress(ByVal sender As Object, ByVal e As
System.Windows. Forms.KeyPressE ventArgs) Handles txtQtyShipped.K eyPress

e.KeyChar = NumericChar(e.K eyChar, , True)

End Sub

Public Function NumericChar(ByV al KeyChar As Char, Optional ByVal
AllowNegative As Boolean = False, Optional ByVal AllowDecimal As Boolean =
False) As Char

Select Case Asc(KeyChar)

Case 8, 48 To 57

NumericChar = KeyChar

Case 45

If AllowNegative = True Then

NumericChar = KeyChar

End If

Case 46

If AllowDecimal = True Then

NumericChar = KeyChar

End If

End Select

End Function

"Peter Newman" <Pe*********@di scussions.micro soft.comwrote in message
news:51******** *************** ***********@mic rosoft.com...
vb.net 2003
i have the following procedure

Private Sub StrLicence_KeyP ress(ByVal sender As Object, ByVal e As
System.Windows. Forms.KeyPressE ventArgs) Handles StrLicence.KeyP ress
Select Case e.KeyChar
Case Microsoft.Visua lBasic.ChrW(13)
MsgBox(" ENTER PRESSED")
' move to next field
Case Microsoft.Visua lBasic.ChrW(8)
MsgBox(" backspace PRESSED")
Case Microsoft.Visua lBasic.ChrW(9)
MsgBox("TAB PRESSED")
' move to next field
Case Microsoft.Visua lBasic.ChrW(48) To
Microsoft.Visua lBasic.ChrW(57)
MsgBox(" NUMBER PRESSED")
Case Else
' show error
MsgBox("MUST BE NUMERIC")
End Select
End Sub

what i want to do is in this case if an alpha charachter is pressed, i
show
the must be numeric message, but i also want to stop that character being
displayed ...

Sep 28 '06 #2
Hi Peter,
By using the e.Handled property you can stop the character output to
the textbox.
Also consider using regular expressions for validation.

Select Case Char.IsDigit(e. KeyChar)
Case True
'/ Valid Character Input
Case False
'/ Invalid Character Input
MessageBox.Show ("Invalid Character Input")
e.Handled = True
End Select
'/ SAME RESULT BUT USING REGULAR EXPRESSIONS
If System.Text.Reg ularExpressions .Regex.IsMatch( e.KeyChar,
"[0-9]") Then
'/ Valid Character Input
Else
'/ Invalid Character Input
MessageBox.Show ("Invalid Character Input")
e.Handled = True
End If

Regards,
Tony

Sep 28 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
4570
by: Karl Ebener | last post by:
Hi! A newbie question: How can I check, whether a key has been pressed and take that input to perform some action? I don't want to wait for that input (=> no Enter needed) and the input should not be displayed. Tnx a lot Karl
2
2618
by: active | last post by:
I have a picturebox usercontrol sitting on a usercontrol. I need a KeyPress event in the PictureBox. I suppose I could have a property in the pictureBox that is accessed by a call in a KeyPressed event in the UserControl. Right? Kind of kludge - is there a more direct way? The usercontrol needs no KeyPress event at all and the Picturebox...
13
6071
by: Himselff | last post by:
Hi guys, Im new to dot net and wondering how i could remake the same way i was in vb6, capture all keypress whitin a form, per exemple i was on the form looking for some keypress privete sub form_keypressed(keyascii as integer) if keyascii = 13 then 'for the enter key call button_click
0
1131
by: ApexData | last post by:
Hello I am interested in learning about "Key Pressed & Key Combination" control! Does anybody have a link to a page that explains this in detail? I am also looking for a list of All the default key combinations that are active when an uncontrolled application executes. ThankYou
6
3351
by: Shirenseru | last post by:
Hi, I recently saw on a website, that there was a possibility that when you're on a certain webpage, and you type like " code " on your keyboard, that some function is being called. Does anyone has experience with this? Cause i would really like some help..
2
2852
by: Memborg | last post by:
Hej Everybody I have tried do make an "instant search" in javascript, ie everytime one hits a key the javascript sends the request to a database and returns the result into a table. The problem is occuring when the result i given. When one do a search the given result is appended to the existing rowx in the table instead of redrawing the...
4
2788
by: pinkfloydhomer | last post by:
I need a function (blocking or non-blocking) that tells me if a key has been pressed (even before it has been released etc.). Also, I would of course like to know _which_ key has been pressed. I know that this probably does not exist in the Python library already as a platform-independant abstraction (even though it probably could), but...
0
7700
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8125
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7676
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.