Click here to Skip to main content
15,867,756 members
Articles / Programming Languages / Visual Basic
Tip/Trick

Clear All textboxes text in VB

Rate me:
Please Sign up or sign in to vote.
4.80/5 (5 votes)
2 Oct 2011CPOL 45.7K   3   4
Clear All textboxes text in VB
If you want to clear all the textboxes in VB, then instead of setting property of each by calling the name we can set it by using the below code. In this, we will read all the controls and if the control is a textbox, then we set it to blank.

VB
Dim X As Control
For Each X In Me.Controls
    If TypeOf X Is TextBox Then
        X = ""
    End If
Next X

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) NICE Computers
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralRecursion is an elegant solution, I'll vote 5. Pin
alxmedina3-Oct-11 10:47
alxmedina3-Oct-11 10:47 
GeneralWrite the above code in c# Pin
AjayAnirudhSingh29-Sep-11 18:56
AjayAnirudhSingh29-Sep-11 18:56 
GeneralRe: public void ClearTextBoxes(Control control) { ... Pin
Mithun Thakur From NICE Computers30-Sep-11 0:07
professionalMithun Thakur From NICE Computers30-Sep-11 0:07 
GeneralReason for my vote of 3 Controls can form a hierarchy as in ... Pin
Luc Pattyn29-Sep-11 2:08
sitebuilderLuc Pattyn29-Sep-11 2:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.