Clearing Text Controls using VB.Net with For Loop Statement

3
126

Clearing Text Controls using VB.Net with For Loop Statement

In this tutorial, you will learn how to Clearing Text Controls using VB.Net with For Loop Statement easily without making any long codes just to clear all the controls inside your form.

First you need to open your Microsoft Visual Studio IDE and create new project, name it as you please.

Then, drag the objects like textbox and combobox in your blank form as many as you like.

Next, create a button. After creating a button or dragged from the toolbox, double click that textbox and insert this line of code.

  1. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  2.  
  3. Dim clean as Control
  4.  
  5. For Each clean In Me.Controls
  6. If TypeOf clean Is TextBox Then
  7. clean.Text = Nothing
  8. End If
  9. Next
  10.  
  11. End Sub

Run your system and see for yourself that after clicking your button, the textboxes inside the form are being cleared.

You can also apply this line of code if you want to clear comboboxes, here’s the sample line of code with clearing all combobox in your form:

  1. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  2.  
  3. Dim clean as Control
  4.  
  5. For Each clean In Me.Controls
  6. If TypeOf clean Is TextBox Then
  7. clean.Text = Nothing
  8. ElseIf TypeOf clean Is ComboBox then
  9. clean.text = Nothing
  10. End If
  11. Next
  12.  
  13. End Sub

You have created your own Clearing Text Controls using VB.Net with For Loop Statement.

RAR Extraction Password:

Password: luffypirates

For questions or any other concerns or thesis/capstone creation with documentation, you can contact me through the following:

E-Mail: [email protected]

Facebook: facebook.com/kirk.lavapiez

Contact No.: +639771069640

To download the project sample code, click here.

Ian Hero L. Lavapiez

BSIT Graduate

System Analyst and Developer

Related topic(s) that you may like:

 

 

Facebook Comments

3 COMMENTS

  1. nice tut sir, if you dont mid..plz can u post another tut this time about “Transfering multiple data from datagridview rows to mysql database” using vb.net as PL thank you and more power!.

LEAVE A REPLY

Please enter your comment!
Please enter your name here