Clearing of Multiple Textboxes in just a Click Using Visual Basic 2008
Submitted by janobe on Tuesday, December 17, 2013 - 19:31.
If you are a beginner in Programming Languages and you’re using Visual Basic, this tutorial will help you minimize your code and lessen your work. This procedure is to clear all the data in the TextBoxes in a certain Form, for example, when you create a “User Entry” Form.
So let’s begin: First let’s create a Form, then put all the TextBoxes you need. Double click the Form, then you have to create a Public Sub and it will look like this.
Description: By using this code, all data in the TextBoxes that can be seen in a Form will all be cleared.
Go back to the Design Views, then double click the Clear Button and call the Sub Name in the Public Sub that you’ve created. It will look like this.
“Me” is an object, which stands as a Form.
Now run your project.
You can also download the Source Code of this project and run it on your computer.
So let’s begin: First let’s create a Form, then put all the TextBoxes you need. Double click the Form, then you have to create a Public Sub and it will look like this.
- 'create your Sub procedure named "clearall" with a parameters type as object.
- Public Sub clearall(ByVal form As Object)
- 'for each txt as control in form(object).control
- For Each txt As Control In form.Controls
- 'conditioning the txt as control by getting it's type.
- 'the type of txt as control must be textbox.
- If txt.GetType Is GetType(TextBox) Then
- 'if the object(textbox) is present. The result is, the textbox will be cleared.
- txt.Text = Nothing
- End If
- Next
- End Sub
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- 'confirming that the data will be clear
- 'call your Sub name.
- clearall(Me)
- End Sub
Add new comment
- 26 views