+ Reply to Thread
Results 1 to 8 of 8

a custom collection with code producing analagous worksheets(1) or worksheets("

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-13-2016
    Location
    CT USA
    MS-Off Ver
    office 365 subscription
    Posts
    180

    a custom collection with code producing analagous worksheets(1) or worksheets("

    Good Morning Folks,

    I have created a custom collection which enables me to get at one of the items in the collection
    but the code that i use is not as straightforward as worksheets(1) or worksheets("name")

    my code requires writing, Floors.Floor(1). I would prefer writing my custom collection class that results in Floors(1) or Floors("name"). Code seems more understandable.

    if you can see how to do that, instead of giving me the answer right away, please offer a hint
    that gives me something to think with so that maybe i might be able to derive the solution you would have provided me. I will probably better remember the solution that way.

    here is the code i have written so far that gets me at least Floors.Floor(1)

        With aHouse.Floors
            For i = 1 To .Count
                MsgBox "aHouse.Floors(" & i & ").Name = " & .Floor(i).Name
            Next
         End With
    VBA executes the above by getting the collection, Floors
    then executes a Floor Collection property of get Floor

           Public Property Get Floor(ByVal value As Variant) As Floor_Class  
                Set Floor = GFloorCollection(value)
           End Property

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,996

    Re: a custom collection with code producing analagous worksheets(1) or worksheets("

    Hint: worksheets(1) is actually short for worksheets.Item(1) with the Item property being the default property.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Forum Contributor
    Join Date
    02-13-2016
    Location
    CT USA
    MS-Off Ver
    office 365 subscription
    Posts
    180

    Re: a custom collection with code producing analagous worksheets(1) or worksheets("

    Thank you Rory.....let me chew on that hint....Thank you for hinting....

  4. #4
    Forum Contributor
    Join Date
    02-13-2016
    Location
    CT USA
    MS-Off Ver
    office 365 subscription
    Posts
    180

    Re: a custom collection with code producing analagous worksheets(1) or worksheets("

    Good Afternoon Rory !

    Thank you for responding.

    I have been on an interesting journey that extended beyond "how" to "what do i want" and "why does my code seem so unclear"


    Due to your hint (thank goodness you used italic font), i began the search. i found chip Pearson's article on Default member of a class as well as other similar articles.

    Before I try coding with the default (as a learning experience), i have a few questions i want to run by you.

    the default code (attribute) is not visible. Hence when things go wrong, i may not understand why. Is this a valid worry from your experience?

    When i look at "worksheets.item(1)" i think , Given a collection (called Worksheets), give me the first item in that collection. That IS clear though more chance for error.
    When i look at my code, Floors.Floor(1), i should think, Given a collection (called Floors) give me the first Floor in the collection. Not bad when i hear that explanation.

    So, Rory, tell me what your choice is in programming. Do you use defaults and does their invisibility both you?

    bil

    BUT my example in my code is not as clear. Floors.Floor(1)



    Another interesting thought

  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,996

    Re: a custom collection with code producing analagous worksheets(1) or worksheets("

    I don't actually use classes very much in real work, since most of what I do is procedural programming, so I'm not best placed to comment, but the invisibility of certain attributes has never worried me or caused me any issues when I have used them.

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: a custom collection with code producing analagous worksheets(1) or worksheets("


    Quote Originally Posted by whburling View Post
    my code requires writing, Floors.Floor(1). I would prefer writing my custom collection class that results in Floors(1) or Floors("name").
    Hello,

    so to make Floor the default property you must export and delete your class module
    then add a specific Attribute codeline within the exported text file
    then you can reimport the class module text file,
    see the Item property sample within the attachment of this thread

  7. #7
    Forum Contributor
    Join Date
    02-13-2016
    Location
    CT USA
    MS-Off Ver
    office 365 subscription
    Posts
    180

    Re: a custom collection with code producing analagous worksheets(1) or worksheets("

    Thank you, Marc....
    I do understand what to do after Rory gave me a hint. I did appreciate your example, however. Thank you.

    Where i am coming from, now, is should i worry about using code (such as that used with Attribute) that can not be seen in the vba environment....since i am an absolute novice, i
    need to hear from people who are more experienced...What is your opinion? do you might using code that can not be seen in the vba environment?

    bil

  8. #8
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: a custom collection with code producing analagous worksheets(1) or worksheets("


    Yes this kind of Attribute line is not a VBA codeline, used only by VBE at the import / export level …
    So it is totally normal to not see this kind of line within the class module, take it as a specific parameter setting.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 4
    Last Post: 10-30-2015, 01:30 PM
  2. [SOLVED] VBA Macro Code to perform Format>Custom & Number for 100+ Worksheets ?
    By mave27 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-07-2015, 06:58 PM
  3. [SOLVED] For loop through Worksheets collection
    By amphinomos in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-31-2014, 08:23 AM
  4. [SOLVED] Edit the code so that it loops through all worksheets and deletes column with "grand" text
    By rocksan in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-13-2012, 02:58 AM
  5. Replies: 1
    Last Post: 06-23-2012, 12:12 PM
  6. Define a collection of worksheets
    By mcinnes01 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 12-22-2010, 11:34 AM
  7. [SOLVED] VBA code to create "variable" worksheets within a workbook
    By Chris in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-13-2005, 10:05 PM

Tags for this Thread

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