Click here to Skip to main content
16,018,417 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hei guys
this is the sample code of mine
VB
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        If Not IsNumeric(TextBox1.Text) Then
hehe:
            Dim abc As DialogResult = MessageBox.Show("Please insert numeric only!", "Error!!", MessageBoxButtons.OKCancel)
            If abc = DialogResult.OK Then
                TextBox1.Clear()
            Else
                GoTo hehe
            End If
        End If
    End Sub


after i press on the ok button..
my text have been clear..
but the problem is the message box still pop out
what show i do to prevent the messagebox pop out again when the ok button is clicked
Posted
Updated 18-Feb-13 0:02am
v4
Comments
Abhinav S 18-Feb-13 5:56am    
Something seems to be missing. Appears as if you are calling the same method again and again.
Post complete / more code here.
arnoldxx 18-Feb-13 6:02am    
done..
this is my complete code~

I suggest you:
1) to use TextBox_Leave[^] event, not TextBox_TextChange[^] event.
2) do not remove text from TextBox, but select it and bring focus back into TextBox,
3) use RegEx[^] to check if TextBox "value" is numeric value.
 
Share this answer
 
Hi,

The message box appearing, because, once you clear the textbox, again its a textchange event, so, it is becoming an infinite function.
so, try below code.
VB
If TextBox1.Text.Trim <> "" Then
    If Not IsNumeric(TextBox1.Text) Then
            Dim abc As DialogResult = MessageBox.Show("Please insert numeric only!", "Error!!", MessageBoxButtons.OKCancel)
            If abc = DialogResult.OK Then
                TextBox1.Clear()
            End If
    End If
End If


hope it helps
 
Share this answer
 
v2
Comments
arnoldxx 18-Feb-13 9:48am    
thx.. btw..
what is the function of <>
Karthik Harve 18-Feb-13 23:09pm    
welcome.
arnoldxx 18-Feb-13 9:54am    
sorry i mean trim *
Karthik Harve 18-Feb-13 23:08pm    
it will trim the textbox text if any spaces on both the ends.
arnoldxx 19-Feb-13 1:34am    
ic...
thx lot for helping me.. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900