borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Close Exe program)Next Topic (Winsock & File transfer) New Topic New Poll Post Reply
AndreaVB Forum : Frequently Asked Questions : A useful tip for controls
Poster Message
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1616

icon A useful tip for controls

Not sure if anyone knows this, or wants to know, but it's somewhat useful (there's been some discussions of how to access a form/control by it's name...):


' This is used in a program where the CtlName is a common
' String in a label and comboboxes
Private Sub EnableOption(ByVal CtlName As String, Optional ByVal fEnabled As Boolean = True)
    Dim ctl As Control
    
    Set ctl = Me.Controls("cbo" & CtlName & "From")
    ctl.Enabled = fEnabled
    
    Set ctl = Me.Controls("cbo" & CtlName & "To")
    ctl.Enabled = fEnabled
    
    Set ctl = Me.Controls("lbl" & CtlName & "Hours")
    ctl.Enabled = fEnabled
    
    Set ctl = Me.Controls("lbl" & CtlName & "To")
    ctl.Enabled = fEnabled
    
    Set ctl = Nothing
End Sub



____________________________
Everywhere's Local (classifieds, job postings, & more for everycity in the world - user entered)

04-07-2003 at 11:00 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
win_dir
Level: VB Guru

Registered: 04-08-2002
Posts: 390
icon Re: A useful tip for controls

ahhhh, it would've actually been extremely useful to me on several occasions. Why don't you "copy" this to the FAQ's board?

____________________________
We have a Mustek 5 M/Pix GSm@rt USB Digital Camera
for just £74.03 , offer only on until 30th February!

<AllDuck.com>      

Enquiries/Sales: 0845 430 9862
Fax: 0870 950 4532

08-07-2003 at 04:57 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
steve_w
Level: Moderator


Registered: 18-04-2003
Posts: 1156
icon Re: A useful tip for controls

Also

If you have a load text boxes on a form that you want to clear use the following code



Dim c As Control

For Each c In Controls
   If TypeOf c Is TextBox Then
      c.Text = ""
   End If
Next

05-08-2003 at 03:48 PM
View Profile Send Email to User Show All Posts | Quote Reply
yronium
Level: Moderator


Registered: 14-04-2002
Posts: 907
icon Re: A useful tip for controls

quote:
steve_w wrote:
Also

If you have a load text boxes on a form that you want to clear use the following code



Dim c As Control

For Each c In Controls
   If TypeOf c Is TextBox Then
      c.Text = ""
   End If
Next




... just a hint...
The code above contains a bug.
If a given textbox is hidden, that code results an error, that has to be handled:

Dim c As Control

On Error Resume Next   ' takes care of hidden controls
For Each c In Controls
   If TypeOf c Is TextBox Then
      c.Text = ""
   End If
Next


  

____________________________
Real Programmer can count up to 1024 on his fingers
11-08-2003 at 12:54 PM
View Profile Send Email to User Show All Posts | Quote Reply
vbgen
Level: Moderator

Registered: 10-10-2002
Posts: 876
icon Re: A useful tip for controls

well, yronium, you din't quite handle the error now, did you?



____________________________
Been busy trying to take a second degree <--it's not working out...

11-08-2003 at 05:30 PM
View Profile Send Email to User Show All Posts | Quote Reply
yronium
Level: Moderator


Registered: 14-04-2002
Posts: 907
icon Re: A useful tip for controls

Yeah, right, "handle" was not the correct word....

...Well, I meant "to manage", or better "to intercept", "to know", ... "to be aware of"... (OK, you got it, and forgive my poor english)



____________________________
Real Programmer can count up to 1024 on his fingers

12-08-2003 at 12:09 PM
View Profile Send Email to User Show All Posts | Quote Reply
vbgen
Level: Moderator

Registered: 10-10-2002
Posts: 876
icon Re: A useful tip for controls

hey, i was just kidding you!
    

hahahaha... peace, dude!

(i usually do that anyway... just using resume next...   )

[Edited by vbgen on 12-08-2003 at 11:29 PM GMT]

____________________________
Been busy trying to take a second degree <--it's not working out...

12-08-2003 at 03:25 PM
View Profile Send Email to User Show All Posts | Quote Reply
fabulous
Level: VB Guru


Registered: 03-08-2002
Posts: 439
icon Re: A useful tip for controls

quote:
steve_w wrote:
Also

If you have a load text boxes on a form that you want to clear use the following code



Dim c As Control

For Each c In Controls
   If TypeOf c Is TextBox Then
      c.Text = ""
   End If
Next




What I do to clear a whole bunch of text boxes and other controls is in a Utility.BAS or UI.bas module have the subroutines that follow the following format.


Public Sub HideControls(ParamArray Ctrls() as Variant)
  On Error Resume Next 'to ignore the errors raised by invalid parameters
  Dim Ctrl as Variant
  For Each Ctrl In Ctrls
    Ctrl.Visible = False
  Next
End Sub

Public Sub HideControlArray(Ctrls As Object)
  Dim Ctrl As Variant
  On Error Resume Next
  For Each Ctrl In Ctrls
    Ctrl.Visible = False
  Next
End Sub


You could have different versions for clearing text boxes, for showing, disabling and enabling and they are accessible from
anywhere. Calling is like this:


HideControls mnuAdmin, cmdNewUser, cmdDelete
'or if it is in a control array
HideControlArray cmdBuittons 'where cmdButtons is a control array of buttons


____________________________
My boss is a Jewish Carpenter (Jesus Christ)


Brain Bench Certified VB.NET Developer
27-01-2004 at 12:27 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
AndreaVB Forum : Frequently Asked Questions : A useful tip for controls
Previous Topic (Close Exe program)Next Topic (Winsock & File transfer) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder