Sunday 22 September 2013

How to enable, disable controls in your form in Visual Basic 6.0

' procedure will take parameters as following
  form object, enable or disable flag, types of controls to be enabled or disabled

option explicit
Private sub EnableDisableControls(frm as Object,flag as Boolean,ParamArray arg() as Variant)
   dim ctl
'   loop starts to fetch all controls in the form object
   for each ctl in frm.Controls
        dim i as integer
  'inner loop starts to navigate through arg from lower bound to upperbound for all the typename parameters passed by in the procedure

        for i=lbound(arg) to ubound(arg)
'typename return control type name, if it matches with the typename send in the argument then ctl.enabled state is set to flag value.
            if vba.lcase(vba.typename(ctl)) = vba.lcase(arg(i)) then
                 ctl.Enabled = flag
                 doevents
           end if
        next i
   next ctl
End Sub

No comments: