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]
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 formDetermines if the current control in the iteration loop is a type of textboxif so, it will do a direct cast, to make a textbox locally and clear the contents of that textbox on the formdoes this help?