Sunday, January 22, 2017

How to clear all TextBoxes on a Form in VB.net

This is a tutorial on how to clear all TextBoxes on a form in Visual Basic .NET.
Instead of calling each TextBox by its name and clear them one by one, you can use a For Each loop that clears all the TextBoxes found on the form



Here is the code that clears all TextBoxes text on a form 


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


        Dim a As Control


        For Each a In Me.Controls


            If TypeOf a Is TextBox Then


                a.Text = Nothing


            End If


        Next


    End Sub


You can also specify textboxes in a groupbox to be cleared. In the following example we will clear all textboxes in GroupBox1 only




Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
 
        Dim a As Control
 
        For Each a In Me.GroupBox1.Controls
 
            If TypeOf a Is TextBox Then
 
                a.Text = Nothing
 
            End If
 
        Next
 
    End Sub

What is Microsoft .Net Framework

The Microsoft .Net Framework is a platform that provides tools and technologies you need to build Networked Applications as well as Distributed Web Services and Web Applications. The .Net Framework provides the necessary compile time and run-time foundation to build and run any language that conforms to the Common Language Specification (CLS).The main two components of .Net Framework are Common Language Runtime (CLR) and .Net Framework Class Library (FCL).
The Common Language Runtime (CLR) is the runtime environment of the .Net Framework , that executes and manages all running code like a Virtual Machine. The .Net Framework Class Library (FCL) is a huge collection of language-independent and type-safe reusable classes. The .Net Framework Class Libraries (FCL) are arranged into a logical grouping according to their functionality and usability is called Namespaces. The following lessosns describes how to .Net Framework manages the code in compile time and run time .