Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links

Numeric TextBox in VB.NET

Software Development

Thread Tools Search this Thread
Old 22-12-2008
Join Date: Aug 2008
Posts: 145
Numeric TextBox in VB.NET

It is a very simple coding for entering numeric value in a text box (VB.NET)

Step1 : Place a TextBox(TextBox1) on your form.

Step2 : Create a function (say TrapKey) for Checking the Values entered.

Step3: Call this function in the KeyPress event of TextBox1.

This has been explained below:

Private Function TrapKey(ByVal KCode As String) As Boolean

If (KCode >= 48 And KCode <= 57) Or KCode = 8 Then 

'The AsCII values for numbers are between 48 to 57 and ASCII value 8 is for BackSpace.

TrapKey = False


TrapKey = True

End If

End Function

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress

e.Handled = TrapKey(Asc(e.KeyChar))

End Sub

Reply With Quote

  TechArena Community > Software > Software Development
Tags: , ,

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads for: "Numeric TextBox in VB.NET"
Thread Thread Starter Forum Replies Last Post
Can Not Use Numeric Keypad On P505D Seema Bhati Portable Devices 5 15-01-2011 06:43 PM
Excel/VBA: Copying text from UserForm Textbox to a Worksheet Textbox Neil Ives Software Development 2 20-08-2010 01:23 AM
Touchscreen with numeric keyboard. Triple-X Portable Devices 3 12-10-2009 03:14 PM
How to check if value is numeric javascript Paramartha Software Development 3 10-08-2009 03:34 PM
Error: "Arithmetic overflow error converting numeric to data type numeric." Nthing Software Development 3 11-06-2009 10:23 AM

All times are GMT +5.5. The time now is 06:02 AM.