Removing Numbers in Textbox using VB.Net
This tutorial is all about Removing Numbers in Textbox using VB.Net With this tutorial about Removing Numbers in Textbox using VB.Net which we can clear number in the textbox.
The variable tmpString was created with an empty string. After that, we created a For Next loop with variable I as an integer equal to zero up to the textbox’s length minus 1.
We placed an If statement inside the loop that says if the textbox has a number, it will be automatically removed. Not returns a Boolean value indicating whether an expression can be evaluated as a number.
IsNumeric returns a Boolean value indicating whether an expression can be evaluated as a number, and Substring – restores the first argument’s substring beginning at the position specified in the second argument and ending at the length specified in the third argument.
So let’s get started:
- This tutorial is a continuation of Allowing Numbers only in Textbox Using VB.Net.
- So let’s design our form like this one just like what I’ve shown you below
Select a Textbox, Button and label from the toolbox.
- After that,Add this code to the Button.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim rep As String = String.Empty
For i As Integer = 0 To TextBox1.Text.Length – 1
If Not IsNumeric(TextBox1.Text.Substring(i, 1)) Then
rep += TextBox1.Text.Substring(i, 1)
TextBox1.Text = rep
- After that, Click F5 to run the program.
- After clicking the button:
If you have any comments or suggestions about on Removing Numbers in Textbox using VB.Net Please feel free to contact our webpage.
Download Removing Numbers in Textbox using VB.Net Code here
Readers might read also: