I am trying to per textchanged in a textbox call an isnumeric function. I cant seem to get it to work.

function:
[ Private Function IsNumericCheck(ByVal CheckVal As String) As String

'check for numeric values and return boolean

If IsNumeric(CheckVal) = False Then
Return False
Else
Return True
End If

End Function]

text changed
[Private Sub tHeight_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tHeight.TextChanged

'set variable
CheckVal = tHeight.Text
'call isnumeric function
IsNumericCheck(CheckVal)

If False Then
MessageBox.Show("Only Enter Nunmeric Values")
End If
End Sub]

what r u trying to do..?
do u want the user to enter only numeric values?

instead of checking all the time the whole text you can use this code:

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If Not Char.IsNumber(e.KeyChar) Then
            e.Handled = True
        End If
    End Sub

this will allow only numbers beeing written in the textbox and ignores everything else

instead of checking all the time the whole text you can use this code:

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If Not Char.IsNumber(e.KeyChar) Then
            e.Handled = True
        End If
    End Sub

this will allow only numbers beeing written in the textbox and ignores everything else

Thank you that works great...

then please mark this thread as solved. ty =)

instead of checking all the time the whole text you can use this code:

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If Not Char.IsNumber(e.KeyChar) Then
            e.Handled = True
        End If
    End Sub

this will allow only numbers beeing written in the textbox and ignores everything else

The probleme here is when we want to remove a number using "Delete Key" they'll not delete because it's counting as a alphabet So We should have a Soulition here to this problem :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.