943,587 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 1552
  • VB.NET RSS
Jan 23rd, 2009
0

Related To Textbox

Expand Post »
Hi Friends

i am using vb.net & i have a textbox on that ,I want only numeric value on that textbox & if i type alfabetical on that textbox so that must give me a message to that type numeric value only

I m not able to doing this plz help me
Reputation Points: 10
Solved Threads: 2
Light Poster
manoj_582033 is offline Offline
39 posts
since Nov 2008
Jan 23rd, 2009
0

Re: Related To Textbox

VB.NET Syntax (Toggle Plain Text)
  1. Private Sub textBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles textBox.KeyPress
  2.  
  3. If Char.IsNumber(e.KeyChar) Or Asc(e.KeyChar) = 8 Then
  4. e.Handled = False
  5. Else
  6. e.Handled = True
  7. MsgBox("Numeric Values Only", MsgBoxStyle.OkOnly + MsgBoxStyle.Information, "Input Error")
  8. End If
  9.  
  10. End Sub

basicly the IsNumber is numbers 0-9, it also allows the delete button, and the ASCII key 8 is the back space key
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tickle69 is offline Offline
3 posts
since Jan 2009
Jan 25th, 2009
0

Re: Related To Textbox

This following code just allowed you to entered numbers only (No alphabetics or any special characters) :
vb.net Syntax (Toggle Plain Text)
  1. Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
  2. If (Microsoft.VisualBasic.Asc(e.KeyChar) < 48) _
  3. Or (Microsoft.VisualBasic.Asc(e.KeyChar) > 57) Then
  4. e.Handled = True
  5. End If
  6. If (Microsoft.VisualBasic.Asc(e.KeyChar) = 8) Then
  7. e.Handled = False
  8. End If
  9. End Sub
Reputation Points: 1182
Solved Threads: 392
Posting Sensei
Jx_Man is offline Offline
3,138 posts
since Nov 2007
Jan 25th, 2009
0

Re: Related To Textbox

well that is what you asked for

use google

VB.NET Syntax (Toggle Plain Text)
  1. If Char.IsNumber(e.KeyChar)Then
  2.  
  3. Else
  4. MsgBox("Numeric Values Only", MsgBoxStyle.OkOnly + MsgBoxStyle.Information, "Input Error")
  5. End If

try that, the e.Handled = False/True determins wether the charater is to be imputted - so just simply remove it
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tickle69 is offline Offline
3 posts
since Jan 2009
Jan 27th, 2009
0

Re: Related To Textbox

HI

You can control that text box by this way

Private Sub tbxNumeric_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles tbxNumeric.KeyPress
StringManipulation.SetTextboxAllowedCharacters("0123456789.", e)

End Sub
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jalpaeol is offline Offline
5 posts
since Oct 2008
Jan 27th, 2009
0

Re: Related To Textbox

Sorry that function is like this

Shared Sub SetTextboxAllowedCharacters(ByVal CharactersAllowed As String, ByRef e As System.Windows.Forms.KeyPressEventArgs, Optional ByVal enter As Boolean = True, Optional ByVal BackSpace As Boolean = True)
VB.NET Syntax (Toggle Plain Text)
  1. Dim err As Integer = 0
  2. If InStr(CharactersAllowed, e.KeyChar.ToString.ToUpper) = 0 Then
  3. err = 1
  4. If enter And Asc(e.KeyChar) = Keys.Enter Then err = 0
  5. If BackSpace And Asc(e.KeyChar) = Keys.Back Then err = 0
  6. If Asc(e.KeyChar) = 3 Then err = 0
  7. If Asc(e.KeyChar) = 22 Then err = 0
  8. End If
  9. If err = 1 Then
  10. e.Handled = True
  11. End If
  12. End Sub
thanks
Last edited by Ancient Dragon; Jan 28th, 2009 at 7:52 pm. Reason: add code tags
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jalpaeol is offline Offline
5 posts
since Oct 2008
Jan 28th, 2009
0

Re: Related To Textbox

you can also use the required field validators in the toolbox

regardless this thread should be marked as solved
Reputation Points: 155
Solved Threads: 41
Posting Whiz in Training
rapture is offline Offline
294 posts
since Jul 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: How To Add Multiple Rows In A Datatable
Next Thread in VB.NET Forum Timeline: how to make execution file in microsoft visual studio





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC