Clear textboxes, pass in a form

bfsog

Well-known member
Joined
Apr 21, 2005
Messages
50
Location
UK
Programming Experience
5-10
Hi.

I have the following code, which when executed will clear all text boxes on a particular form. However, I have more than one form which will need this feature.

VB.NET:
		Dim ctrl As Control
		For Each ctrl In Controls
			If TypeOf ctrl Is TextBox Then ctrl.Text = ""
		Next ctrl

How would I implement this as a function so that I can save it in a module?

Ideally I would like to call it like this..

VB.NET:
ClearFields(FormName)

Any help is greatly appreciated.
 
VB.NET:
'Public Module:
Friend Sub ClearText(byref Form as System.Windows.Forms.Form)
  Dim ctrl As Control
  For Each ctrl In Form.Controls
	If TypeOf ctrl Is TextBox Then ctrl.Text = ""
  Next ctrl
End Sub

'A form in the project:
Call ClearText(Me)
 
Back
Top