Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB
hei guys
this is the sample code of mine
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 17-Feb-13 23:49pm
Edited 18-Feb-13 0:02am
v4
Comments
Abhinav S at 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 at 18-Feb-13 6:02am
   
done..
this is my complete code~
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
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
  Permalink  
v2
Comments
arnoldxx at 18-Feb-13 9:48am
   
thx.. btw..
what is the function of <>
Karthik Harve at 18-Feb-13 23:09pm
   
welcome.
arnoldxx at 18-Feb-13 9:54am
   
sorry i mean trim *
Karthik Harve at 18-Feb-13 23:08pm
   
it will trim the textbox text if any spaces on both the ends.
arnoldxx at 19-Feb-13 1:34am
   
ic...
thx lot for helping me.. :)
Karthik Harve at 19-Feb-13 1:40am
   
welcome .!!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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.
  Permalink  

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

  Print Answers RSS
0 CPallini 385
1 Sergey Alexandrovich Kryukov 262
2 OriginalGriff 200
3 George Jonsson 134
4 Richard MacCutchan 110
0 OriginalGriff 6,344
1 Sergey Alexandrovich Kryukov 5,890
2 CPallini 5,175
3 George Jonsson 3,559
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 18 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100