.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Visual Studio >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

The textbox accept only number.

Posted By:laptop charles       Posted Date: July 29, 2010    Points: 10    Category: Visual Studio    URL: http://www.dotnetspark.com  

Using key listiner to accept only number.
 

*It contain one textbox and keyup listener.
*The following condition accept only number.
Public Class Form1
    Inherits System.Windows.Forms.Form

   

    Private Sub TextBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
        If e.KeyValue <= 48 Or e.KeyValue <= 57 Then

        Else
            MsgBox("It is not a number")
            TextBox1.Text = ""
        End If
    End Sub

    
End Class


     

Further Readings:

Responses
Author: Kunal Chowdhury         Company URL: http://www.dotnetspark.com
Posted Date: August 14, 2010

Hi Charles,

What is the meaning of this line:

If e.KeyValue <= 48 Or e.KeyValue <= 57 Then

You can directly check: If e.KeyValue <= 57 Then

I think, the condition is wrong there. Please update it properly.

Regards,
Kunal



Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend