[program-l] Re: VB6: For Each

  • From: "David Lant" <david.lant1@xxxxxxxxxxxxxx>
  • To: <program-l@xxxxxxxxxxxxx>
  • Date: Fri, 6 Jan 2006 12:51:01 -0000

Hi Jim,
 
It's only problematic in that it isn't quite accurate. <smile>
 
Private Sub xxx(ByRef frm as Form)
        Dim ctrl As Control
 
        For Each ctrl In frm.Controls
        ctrl.enabled = false
        Next

End Sub

Bear in mind the following, which I'm sure you're already aware of:
 
The above code will disable *all* the controls on the form, so you will
presumably want to put in some logic to be selective about which controls to
disable.  Another and slightly quicker way might be to put frames on the
form, and put the controls you want to selectively disable into the frames,
and just disable the frames.  It depends on whether the controls in question
are visually associated or not.
 
Apart from that, it's a technique we use all the time here, and indeed we
have a standard routine we use in all our systems to enable and disable
controls, as well has making them visible and invisible conditional on the
state of the form etc.
 

All the best, 

David 

-----Original Message-----
From: program-l-bounce@xxxxxxxxxxxxx [mailto:program-l-bounce@xxxxxxxxxxxxx]
On Behalf Of Corbett, James
Sent: 06 January 2006 12:37
To: Program-L (E-mail)
Subject: [program-l] VB6: For Each



Hello: 

I need a quick and dirty solution... I have a form with a variety of
controls on it ranging from command buttons to text boxes.

I wish to disable all controls on this form based upon a user level so I
thought I would go about it thus: 

private sub xxx(frm as form) 
        dim ctrl as object 

        with frm 
        for each ctrl in frm 
        ctrl.enabled = false 
        next 
        end with 
end sub 

Ok, its early in the morning here, I have been at my desk for 20 straight
hours, tonnes of coffee and my back teeth are floating... Is the above code
problematic?

J. 

James M. Corbett 

(613) 941-8303 | facsimile / télécopieur 613 941-8720 | TTY/ATS
1-800-665-0354 
James.Corbett@xxxxxxxxxxxxxxx 
IT Programmer/Analyst | GST/HST Division | Information Technology Branch
Programmeur/Analyste en technologie de l'information | Division de la
TPS/TVH | Direction générale de l'informatique
Canada Revenue Agency | 875 Heron Rd., Ottawa, ON K1A 0L5 
Agence du revenu du Canada | 875 Ch. Heron, Ottawa ON K1A 0L5 
Government of Canada | Gouvernement du Canada 



"did you exchange a walk on part in the war for a lead role in a cage" 

Pink Floyd ... "Wish you were here" 



Other related posts: