Remove all numbers in the TextBox

Submitted by: 
Language: 
Visitors have accessed this post 254 times.

This is a tutorial in which if we input a number or numbers in the textbox, it will remove or clear those numbers if we will click the remove button.

Now, let's start this tutorial!

1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application.

2. Next, add only one Button named Button1 and labeled it as "Remove All Numbers" and one TextBox named TextBox1 that will serve as our input. You must design your interface like this:

design

3. Now put this code for your code module. This code is for Button1_Click:

  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2. Dim tmpString As String = Nothing
  3. For i As Integer = 0 To TextBox1.Text.Length - 1
  4. If Not IsNumeric(TextBox1.Text.Substring(i, 1)) Then
  5. tmpString = tmpString + TextBox1.Text.Substring(i, 1)
  6. End If
  7. Next
  8. TextBox1.Text = tmpString
  9. End Sub

Explanation:

We have initialized variable tmpString as an empty string. Then we have created a For Next loop that variable i as integer will be equal to zero up to the length of the textbox minus 1. Inside the loop, we have created an If statement that if the textbox contains a number then it will remove it as we have this line of code

  1. For i As Integer = 0 To TextBox1.Text.Length - 1
  2. If Not IsNumeric(TextBox1.Text.Substring(i, 1)) Then
  3. tmpString = tmpString + TextBox1.Text.Substring(i, 1)
  4. End If
  5. Next

Not - a code for negation.
IsNumeric - returns a Boolean value indicating whether an expression can be evaluated as a number.
Substring - returns the substring of the first argument starting at the position specified in the second argument and the length specified in the third argument.

Output:

outputoutput

Download the source code below and try it! :)

For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.

Best Regards,

Engr. Lyndon Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer
Mobile: 09488225971
Landline: 826-9296
E-mail:[email protected]

Add and Follow me on Facebook: https://www.facebook.com/donzzsky

Visit and like my page on Facebook at: https://www.facebook.com/BermzISware


Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.