Results 1 to 6 of 6
  1. #1
    Star Lounger
    Join Date
    Sep 2001
    Location
    Pittsburgh, Pennsylvania
    Posts
    64
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Control Array Question (VB6)

    Is there a way to perform an operation on an entire control array, without specifying each member of the array?

    For instance, I want to clear all of the text boxes in a control array with one statement such as "TextBox.Text = "". Can this be done?

  2. #2
    4 Star Lounger
    Join Date
    Aug 2002
    Location
    Dallas, Texas, USA
    Posts
    594
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Control Array Question (VB6)

    As far as I know, no. If you think about it, you are sharing names between the items in the array, but each instance of the object is it's own seperate object.

    The best method is to just use a for each or for next loop to loop through the controls.

  3. #3
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Control Array Question (VB6)

    As Drew says, you need a for each loop:
    <pre>Option Explicit

    Private Sub Form_Load()
    Dim c As Control
    For Each c In Controls
    If TypeOf c Is TextBox Then _
    c.Text = ""
    Next c
    End Sub</pre>

    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  4. #4
    Star Lounger
    Join Date
    Sep 2001
    Location
    Pittsburgh, Pennsylvania
    Posts
    64
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Control Array Question (VB6)

    Thanks for the prompt responses, guys. That was just what I needed. As a reward, I'll let you solve another one.

    How can I get a label caption to show the rightmost zero after a decimal? For example,

    lblPay.Caption = "$" & (lblHours.Caption * 10.15)

    If lblHours.Caption is 10, then lblPay.Caption shows $101.5. I want it to display $101.50.

    I have tried setting the DataFormat property to currency and number with 2 decimal places.

    Any thoughts? Thanks.

  5. #5
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Control Array Question (VB6)

    Use FormatCurrency. You can leave the number of decimal places blank and it will default to your windows setting or you can specify two. It's a pain, but label controls are low overhead controls.
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  6. #6
    Star Lounger
    Join Date
    Sep 2001
    Location
    Pittsburgh, Pennsylvania
    Posts
    64
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Control Array Question (VB6)

    Thanks, Sam. As always...LOUNGERS RULE!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •