Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb thread: best coding to handle this...


Message #1 by "OB" <oby.atabansi@h...> on Mon, 29 Apr 2002 19:38:48
This is a multi-part message in MIME format.

------=_NextPart_000_0009_01C1F030.B97C1DA0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I am just giving u a concept not an exact cut paste solution,

Assume u have 3 textboxes Text1, Text2, Text3
2 comboboxes combo1,combo2
2 commandbuttons Command1,Command2

In all u have 7 Controls :--

Create an enum so that each control on the form has a progressive whole 
bit Like this ,

Private Enum EFrmCTL
    TXT_1 =3D 1 '2^0
    TXT_2 =3D 2 ' 2^1
    TXT_3 =3D 4 '2^2
    CBO_1 =3D 8
    CBO_1 =3D 16
    CMD_1 =3D 32
    CMD_2 =3D 64
    TXT_1_A =3D 128 ' where 2 or more props have to be altered for the 
same control
end enum

'Now create Long Consts to represent diff settings depending upon what u 
want enabled/visible 'in each setting
Private Const Setting1 As Long =3D TXT_1 + TXT_3 + CBO_1
Private Const Setting2 As Long =3D TXT_1 + TXT_2 + CMD_1 + TXT_1_A
Private Const Setting3 As Long =3D TXT_2 + TXT_3 + CBO_2 + CMD_2

'In the NodeClick of the treeview Event all u have to do is identify the 
setting that is 'applicable and call this function

Private Function RenderForm(lSetting As Long) As Boolean
    Text1.Enabled =3D (lSetting And TXT_1)
    Text2.Enabled =3D (lSetting And TXT_2)
    Text3.Enabled =3D (lSetting And TXT_3)

    Text1.AnyOtherProp =3D  (lSetting And TXT_1_A)
  
    Combo1.Visible =3D (lSetting And CBO_1)
    Combo2.Visible =3D (lSetting And CBO_2)
   
    Command1.Enabled =3D (lSetting And CMD_1)
    Command2.Enabled =3D (lSetting And CMD_2)
    Command3.Enabled =3D (lSetting And CMD_3)
End Function


if u need to change more than 1 property in the same control then u need 
to append to the enum
and include it in the function as well

Hope this is not beyond you. It has always worked for me.
It can reduce ur code by 100 * (no of settings u need-1) %.
Plus it is based on bitwise operations which are anyway faster anything 
else.

This concept works best upon Properties of Datatype Boolean.


Regards,
AJAX=AE.


----- Original Message -----
From: "Kim, Cardyin" <CKim@s...>
To: "professional vb" <pro_vb@p...>
Sent: Tuesday, April 30, 2002 12:14 AM
Subject: [pro_vb] RE: best coding to handle this...


> A quick suggestion would be to cycle through
> the controls looking for the all the comboboxes.
> If you set the tag property of the combobox to
> have a string of characters.  Each character
> would stand for a particular state that
> applies (EG. "ABD" where "A" would stand for
> General Suspense Parameters, etc)
>
> Check all the comboboxes to see if a particular
> state is found.  If so, set it (and its
> corresponding label) visible, if not, then
> set it invisible
>
> For Each ctlTempControl In Me
>   If TypeOf ctlTempControl Is TextBox Then
>     If InStr(1, ctlTempControl.Tag, "A") > 0 Then
>       'Condition A is true
>       ctlTempControl.Visible =3D True
>       'The next line assumes that for every cboControlName
>       'you have a corresponding lblControlName.
>       Me.Controls("lbl" & Mid(ctlTempControl.Name, 4)).Visible =3D 
True
>     Else
>       ctlTempControl.Visible =3D False
>       Me.Controls("lbl" & Mid(ctlTempControl.Name, 4)).Visible =3D 
False
>     End If
>   End If
> Next ctlTempControl
>
> One word of warning though:  Using the above code
> you will take a performance hit compared to the
> code you have supplied before.  The above
> code will loop through ALL the controls on the
> form everytime you execute it and it uses late
> binding.  Your current code does not use
> any looping and uses early binding.
>
> Hope this helps.
>
> Cardyin
>
> -----------------------------------------
> Cardyin Kim
> Client/Server and Web Development Analyst
> San Antonio Community Hospital
> Upland, California
> ckim@s...        (xxx) xxx-xxxx
> -----------------------------------------
>
>
> -----Original Message-----
> From: OB [mailto:oby.atabansi@h...]
> Sent: Monday, April 29, 2002 12:39 PM
> To: professional vb
> Subject: [pro_vb] best coding to handle this...
>
>
> Obviously, this is too much and unneccesary coding...
>
> What's the best way to handle this?
>
> Public Sub LoadSuspParam(strParam As String)
>     Me.Visible =3D True
>     Me.WindowState =3D vbMaximized
>    
>     Select Case strParam
>         Case "A1"
>             'General suspense Parameters
>             cboRlCd.Visible =3D False
>             lblRlCd.Visible =3D False
>             lblGrpCntRslt.Visible =3D True
>             cboGrpCntRsltBy.Visible =3D True
>             lblDteSrchBy.Visible =3D True
>             cboDteSrchBy.Visible =3D True
>             lblActnTyp.Visible =3D True
>             cboActnTyp.Visible =3D True
>             lblActnOffcr.Visible =3D True
>             cboActOffcr.Visible =3D True
>             ...
>         Case "A2"
>             'External suspense Parameters
>             cboRlCd.Visible =3D True
>             lblRlCd.Visible =3D True
>             lblGrpCntRslt.Visible =3D True
>             cboGrpCntRsltBy.Visible =3D True
>             lblDteSrchBy.Visible =3D True
>             cboDteSrchBy.Visible =3D True
>             lblActnTyp.Visible =3D True
>             cboActnTyp.Visible =3D True
>             ...
>         Case "A3"
>             'Suspense with Special Items Parameter
>             lblDteSrchBy.Visible =3D False
>             cboDteSrchBy.Visible =3D False
>             lblGrpCntRslt.Visible =3D True
>             cboGrpCntRsltBy.Visible =3D True
>             cboRlCd.Visible =3D False
>             lblRlCd.Visible =3D False
>             ...
>
> and it goes on til 'Case A20'. 
>
> Each case node is a tree node is suppose to enable or disable an 
object on
> a form, depending on which tree node is clicked.
>
> Thanks in advance,
>
> Oby.
> to unsubscribe send a blank email to ..
>



  Return to Index