I am confused about how to make a button able to clear the text in all textboxes. I know in c# I can just say textbox1.Clear(); but this won't work in this case.

Please someone help please!

thank you!

Recommended Answers

All 2 Replies

Hi,
Setting the text property to = "" will achieve the same thing. To spend up the process of coding it up (and make your code easily able to handle a growing number of textbooks) use this code in your Clear button

Dim ctrl As Control
Dim txt As TextBox

For Each ctrl In Me.Controls
If (ctrl.GetType() Is GetType(TextBox)) Then
txt = CType(ctrl, TextBox)
txt.Text = ""
End If
Next

This will loop through all if the controls, find text boxes and change their text to "". Only useful if you want to clear out every text box though otherwise you would need to exclude any that held their values.
Hope that helps,

For Each ctl In New TextBox() {TextBox1, TextBox2, TextBox3}
            ctl.Clear()
        Next
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.