Remove all numbers in the TextBox
Submitted by donbermoy on Sunday, March 16, 2014 - 23:11.
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:
3. Now put this code for your code module. This code is for Button1_Click:
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.
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- Dim tmpString As String = Nothing
- For i As Integer = 0 To TextBox1.Text.Length - 1
- tmpString = tmpString + TextBox1.Text.Substring(i, 1)
- End If
- Next
- TextBox1.Text = tmpString
- 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- For i As Integer = 0 To TextBox1.Text.Length - 1
- tmpString = tmpString + TextBox1.Text.Substring(i, 1)
- End If
- Next
Output:
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 R. Bermoy
IT Instructor/System Developer/Android Developer
Mobile: 09079373999
Telephone: 826-9296
E-mail:[email protected]
Visit and like my page on Facebook at: Bermz ISware Solutions
Subscribe at my YouTube Channel at: SerBermz
Add new comment
- 68 views