• Control Array Question (VB6)

    Author
    Topic
    #384380

    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?

    Viewing 1 reply thread
    Author
    Replies
    • #659222

      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.

    • #659228

      As Drew says, you need a for each loop:

      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
      • #659519

        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.

        • #659534

          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.

    Viewing 1 reply thread
    Reply To: Control Array Question (VB6)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: