+ Reply to Thread
Results 1 to 5 of 5

minimizing redundant code

  1. #1
    Registered User
    Join Date
    08-19-2005
    Posts
    58

    minimizing redundant code

    let's say i have some code as follows:

    Please Login or Register  to view this content.
    is there any way to group the different lists so that i only need to write .visible = false once? maybe something like (liste,listw,listc,lists).visible = false.

    what about for with-end with constructions? is there a way i can write:

    Please Login or Register  to view this content.
    or something to that effect?

    thanks.

  2. #2
    Mark Lincoln
    Guest

    Re: minimizing redundant code

    If you're toggling the visibility of a set of controls, you can put the
    code in a Sub and call the Sub. The test that determines visibility
    could be part of the Sub code, or you could set a flag before calling
    the Sub to determine whether .visible is True or False.


  3. #3
    Registered User
    Join Date
    08-19-2005
    Posts
    58
    Quote Originally Posted by Mark Lincoln
    If you're toggling the visibility of a set of controls, you can put the
    code in a Sub and call the Sub. The test that determines visibility
    could be part of the Sub code, or you could set a flag before calling
    the Sub to determine whether .visible is True or False.
    thanks for the reply. that would work, except that in my case, each instance of the group of controls would have different visibility properties, so i'd need to write them out anyway.

    it's simple code. i was just wondering if there was a simpler way.


    how about the second question? is there a simple way to format a group of objects so that they all have the same format?

  4. #4
    Bernie Deitrick
    Guest

    Re: minimizing redundant code

    Generally, you need to do a loop:

    Dim myThing As Whatever

    For Each myThing In WhateverCollection
    myThing.Visible = False
    Next myThing

    That said, there isn't always a collection available, so you often need to improvise

    Dim i As Integer

    For i = 1 To 5
    UserForm1.Controls("CheckBox" & i).Visible = False
    Next i

    And then you would need to pay attention to your naming conventions.


    HTH,
    Bernie
    MS Excel MVP


    "dreamz" <[email protected]> wrote in message
    news:[email protected]...
    >
    > let's say i have some code as follows:
    >
    >
    > Code:
    > --------------------
    > If ComboReg.Value = "National" Then
    > ListNat.Visible = True
    > ListE.Visible = False
    > ListW.Visible = False
    > ListC.Visible = False
    > ListS.Visible = False
    > --------------------
    >
    >
    > is there any way to group the different lists so that i only need to
    > write .visible = false once? maybe something like
    > (liste,listw,listc,lists).visible = false.
    >
    > what about for with-end with constructions? is there a way i can
    > write:
    >
    >
    > Code:
    > --------------------
    > with (liste,listw,listc,lists)
    > insert code
    > end with
    > --------------------
    >
    >
    > or something to that effect?
    >
    > thanks.
    >
    >
    > --
    > dreamz
    > ------------------------------------------------------------------------
    > dreamz's Profile: http://www.excelforum.com/member.php...o&userid=26462
    > View this thread: http://www.excelforum.com/showthread...hreadid=521145
    >




  5. #5
    Mark Lincoln
    Guest

    Re: minimizing redundant code

    > is there a simple way to format a group
    > of objects so that they all have the same format?


    At the risk of striking out completely...

    I've occasionally created an array of control objects and used a
    For-Next loop to set properties. I would flag a control to set its
    property opposite to the others by setting an integer variable to the
    array index of the control in question.

    If you need to set one control of the group to visible and the rest to
    not visible, you might keep track of which control is visible by
    storing it in an object variable. When your situation changes, set the
    visible control to not visible, then set the pertinent control to
    visible and flag it as such.

    I hope this helps a little bit.


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1