Related To Textbox

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2008
Posts: 34
Reputation: manoj_582033 is an unknown quantity at this point 
Solved Threads: 0
manoj_582033 manoj_582033 is offline Offline
Light Poster

Related To Textbox

 
0
  #1
Jan 23rd, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 3
Reputation: tickle69 is an unknown quantity at this point 
Solved Threads: 0
tickle69 tickle69 is offline Offline
Newbie Poster

Re: Related To Textbox

 
0
  #2
Jan 23rd, 2009
  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
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2,641
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Solved Threads: 245
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

Re: Related To Textbox

 
0
  #3
Jan 25th, 2009
This following code just allowed you to entered numbers only (No alphabetics or any special characters) :
  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
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 3
Reputation: tickle69 is an unknown quantity at this point 
Solved Threads: 0
tickle69 tickle69 is offline Offline
Newbie Poster

Re: Related To Textbox

 
0
  #4
Jan 25th, 2009
well that is what you asked for

use google

  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
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 5
Reputation: jalpaeol is an unknown quantity at this point 
Solved Threads: 0
jalpaeol jalpaeol is offline Offline
Newbie Poster

Re: Related To Textbox

 
0
  #5
Jan 27th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 5
Reputation: jalpaeol is an unknown quantity at this point 
Solved Threads: 0
jalpaeol jalpaeol is offline Offline
Newbie Poster

Re: Related To Textbox

 
0
  #6
Jan 27th, 2009
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)
  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
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 276
Reputation: rapture has a spectacular aura about rapture has a spectacular aura about 
Solved Threads: 37
rapture rapture is offline Offline
Posting Whiz in Training

Re: Related To Textbox

 
0
  #7
Jan 28th, 2009
you can also use the required field validators in the toolbox

regardless this thread should be marked as solved
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC