This is a routine that I use to prepare the controls on a form for validation.
The passed container is normally a panel or frame which contains all the 'maintenance' controls.
{text boxes, text areas, combo boxes, checkboxes etc...}
It will then recursivity search for controls and then set their chosen parameters to whatever it is that I need using the
Object.SetProperty & Object.getProperty commands.
This allows you to overcome the limited set of parameters exposed when you examine the child controls.
The main one is to
Trim the text input areas as this overcomes a common problem with user input.
The InColour is used to return the display colour of a control back to a standard. In most cases this is black.
As part of a validation routine, I turn the label for the control red if an error is detected to assist the user in
quickly identifying where the error is.
Public Sub FormPrepareForValidation(InControl As Object, InColor As Integer)
Dim ControlElement As Control
For Each ControlElement In InControl.Children
If ControlElement Is Frame Then FormPrepareForValidation(ControlElement, InColor) ' It may have children so do a recursive search"
If ControlElement Is Panel Then FormPrepareForValidation(ControlElement, InColor) ' It may have children so do a recursive search"
If ControlElement Is Label Then Object.SetProperty(ControlElement, "ForeGround", InColor)
If ControlElement Is TextBox Then Object.SetProperty(ControlElement, "Text", Trim(Object.getProperty(ControlElement, "Text")))
If ControlElement Is TextArea Then Object.SetProperty(ControlElement, "Text", Trim(Object.getProperty(ControlElement, "Text")))
If ControlElement Is RadioButton Then Object.SetProperty(ControlElement, "ForeGround", InColor)
If ControlElement Is CheckBox Then Object.SetProperty(ControlElement, "ForeGround", InColor)
If ControlElement Is TabPanel Then Object.SetProperty(ControlElement, "ForeGround", InColor)
If ControlElement Is TabStrip Then Object.SetProperty(ControlElement, "ForeGround", InColor)
Next
End
This subroutine uses the same concepts to Reset a container's controls, ready to accept new input.
Public Sub FormResetControls(InControl As Container)
Dim ControlElement As Control
Dim ChildControl As Control
Dim TmpInt As Integer
Dim TPanel As TabPanel
Dim TStrip As TabStrip
For Each ControlElement In InControl.Children
If ControlElement Is Frame Then FormResetControls(ControlElement) ' It may have children so do a recursive search
If ControlElement Is Panel Then FormResetControls(ControlElement) ' It may have children so do a recursive search
If ControlElement Is TabPanel Then
TPanel = ControlElement
For TmpInt = 0 To TPanel.Count - 1
FormResetControls(Tpanel[TmpInt]) ' It may have children so do a recursive search
Next
Endif
If ControlElement Is TabStrip Then
TStrip = ControlElement
For TmpInt = 0 To TPanel.Count - 1
FormResetControls(TStrip[TmpInt]) ' It may have children so do a recursive search
Next
Endif
If ControlElement Is TextBox Then Object.SetProperty(ControlElement, "Text", "")
If ControlElement Is TextBox Then Object.SetProperty(ControlElement, "Background", Color.White)
If ControlElement Is TextArea Then Object.SetProperty(ControlElement, "Text", "")
If ControlElement Is TextEditor Then Object.SetProperty(ControlElement, "Text", "")
If ControlElement Is ComboBox Then Object.SetProperty(ControlElement, "Index", 0)
If ControlElement Is ValueBox Then Object.SetProperty(ControlElement, "value", Null)
If ControlElement Is CheckBox Then Object.SetProperty(ControlElement, "value", 0)
If ControlElement Is SpinBox Then Object.SetProperty(ControlElement, "Value", Object.GetProperty(ControlElement, "MinValue"))
Next