Practical Web Programming

Saturday, January 26, 2008

How to Easily Clear the Texts in Textbox or Combobox in Visual Basic

Ever done a program wherein you have to clear all the texts in textboxes and/comboboxes every time you need to input something? If you reference each control by it's name and then clearing the text one by one, that will result to more lines of codes. And in programming, more lines of codes means more complications.

Good thing is, you don't have to write several lines of source codes, the function below will do just that.

This visual basic function will clear texts any control with text property or a list-index property in the form.

Public Sub ClearAllControls(frmForm As Form)
Dim ctlControl As Object
On Error Resume Next
For Each ctlControl In frmForm.Controls
ctlControl.Text = ""
ctlControl.LISTINDEX = -1
DoEvents
Next ctlControl
End Sub

0 comments:

Recent Post