Button To Clear All Text Boxes?

Hi, I am new to this Visual Basic thing and I have a question. I need to make a button to clear all the text boxes on my form. I tried this-

Dim aReset() As String = {"TextBox1", "TextBox2", "TextBox3", "TextBox4", "TextBox5", "TextBox6", "TextBox7", "TextBox8", "TextBox9", "TextBox10", "TextBox11"}
Dim i As Integer = 0

For i = 0 To 10
'set the value to 0
Next i Dim i As Integer = 0

For i = 0 To 10
'set the value to 0
Next i

But this just seems to do nothing. Can anyone give me a bit of help with figuring this out?

Much appreciated.
Derbie

[699 byte] By [Derbie] at [2007-12-24]
# 1

to clear all the textboxes text on your form, you need to iterate through each textbox on the form and then clear out the text:

for each currentControl as Control in Me.Controls

if TypeOf currentControl Is TextBox then

Dim theTextBox as TextBox = DirectCast(currentControl, TextBox)

theTextBox.Text = ""

end if

next

  • Goes through each control on the form

  • Determines if the current control in the iteration loop is a type of textbox

  • if so, it will do a direct cast, to make a textbox locally and clear the contents of that textbox on the form

    does this help?

  • ahmedilyas at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
    # 2
    Thank you very much, I have been trying to figure this one out for a few hours. Working as intended now.

    Thankee very much!
    Derbie

    Derbie at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
    # 3
    excellent, glad I could be of assistance! :-)
    ahmedilyas at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...