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
Private Sub textBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles textBox.KeyPress If Char.IsNumber(e.KeyChar) Or Asc(e.KeyChar) = 8 Then e.Handled = False Else e.Handled = True MsgBox("Numeric Values Only", MsgBoxStyle.OkOnly + MsgBoxStyle.Information, "Input Error") End If 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
This following code just allowed you to entered numbers only (No alphabetics or any special characters) :
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress If (Microsoft.VisualBasic.Asc(e.KeyChar) < 48) _ Or (Microsoft.VisualBasic.Asc(e.KeyChar) > 57) Then e.Handled = True End If If (Microsoft.VisualBasic.Asc(e.KeyChar) = 8) Then e.Handled = False End If End Sub
well that is what you asked for
If Char.IsNumber(e.KeyChar)Then Else MsgBox("Numeric Values Only", MsgBoxStyle.OkOnly + MsgBoxStyle.Information, "Input Error") End If
try that, the e.Handled = False/True determins wether the charater is to be imputted - so just simply remove it
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
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)
Dim err As Integer = 0 If InStr(CharactersAllowed, e.KeyChar.ToString.ToUpper) = 0 Then err = 1 If enter And Asc(e.KeyChar) = Keys.Enter Then err = 0 If BackSpace And Asc(e.KeyChar) = Keys.Back Then err = 0 If Asc(e.KeyChar) = 3 Then err = 0 If Asc(e.KeyChar) = 22 Then err = 0 End If If err = 1 Then e.Handled = True End If End Sub
you can also use the required field validators in the toolbox
regardless this thread should be marked as solved
I want to write out a DXF file with line arc and maybe spline.
My issue is documentation; While I have looked at AutoCAD's site I feel that there isnt ...
Hi Maam and Sir.
I need your expertise on vb.net.
I have two data grid with database on their own. I want to copy/update the data from one database to ...
Hi everyone, I am working on a coin collection app, and I have recently started integrating core data into my app. My app is of the following format: I have ...