+ Reply to Thread
Results 1 to 15 of 15

Class module / multidimensional array?

  1. #1
    Forum Contributor
    Join Date
    06-16-2011
    Location
    London
    MS-Off Ver
    Excel XP
    Posts
    276

    Class module / multidimensional array?

    New to class modules....not sure I really understand them properly.

    What I'm trying to do is create a list of engineers, log the dates each has worked and produce a count of jobs per day to calculate an average with.

    So....what I was thinking of was something like an array of Engineers(1 to 200) as string and two other variables, one being WorkDay(1 to 10000) date and JobDay(1 to 10000) as integer

    However, a co-worker suggested using a class module instead:

    Please Login or Register  to view this content.


    Now, I've managed to get it to create multiple instances of the class:

    Please Login or Register  to view this content.

    And I can read them back in sequential order:

    Please Login or Register  to view this content.

    Now comes the complete bonehead question:

    How do I reference an individual instance of the class in order to assign values to the other variables?
    Like.....if code is scanning through a data set, finds the engineer name, searches the collection for a matching engineer name......how does it assign the date worked to WorkDay(n) of that particular instance?

    Or am I barking up the wrong tree completely and this can be done easily with a multidimensional array (also new to me).


    Google has only managed to get me this far....

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Class module / multidimensional array?

    You need to include an Index parameter in order to specify which element in the array you want to read or write to.

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    The use of JobDay and WorkDay are hard coded in the example as I don't know where you have that data
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Contributor
    Join Date
    06-16-2011
    Location
    London
    MS-Off Ver
    Excel XP
    Posts
    276

    Re: Class module / multidimensional array?

    Thanks Andy, still not getting it though I'm afraid.

    I get the indexing - need that to access the array within the class. How do I access the indexed array JobDay(n) for one particular engineer, ie one specific instance of the class?


    Say I've got 10 instances of the class, each with a different engineer.name
    Each instance has got multiple entries in the array JobDay(n) with a corresponding value in the WorkDay(n) array.

    What I need to do is get the next engineers name from the pre-existing dataset held on a worksheet, search through all the instances of Engineers until I find the one with Engineer.Name = whatever and then search through the JobDay(n) array for that instance to see if there's already an entry matching the date worked from the dataset.....if there is, add 1 to the WorkDay(n) value and if not, add the date worked to the next empty value in the JobDay(n) array and stick a 1 in the same WorkDay(n).

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Class module / multidimensional array?

    Not following your explanation 100%.

    If you use the name, assuming they are unique, as the key then you can set a reference like this.

    Please Login or Register  to view this content.

  5. #5
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Class module / multidimensional array?

    I suspect a collection/dictionary approach may be more useful:
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  6. #6
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Class module / multidimensional array?

    Though to be honest, I'd use a pivot table

  7. #7
    Forum Contributor
    Join Date
    06-16-2011
    Location
    London
    MS-Off Ver
    Excel XP
    Posts
    276

    Re: Class module / multidimensional array?

    Quote Originally Posted by Andy Pope View Post
    Not following your explanation 100%.
    What I mean is, when I'm searching through WorkDay(n) to find a matching date, how to I ensure I'm searching through the correct instance of WorkDay(n) and not the WorkDay(n) array of another engineer?

  8. #8
    Forum Contributor
    Join Date
    06-16-2011
    Location
    London
    MS-Off Ver
    Excel XP
    Posts
    276

    Re: Class module / multidimensional array?

    This is what I've come up with:

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

    However, I'm getting an overflow error trying to add the very first value here:
    Please Login or Register  to view this content.

  9. #9
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Class module / multidimensional array?

    Doesn't mine do that?

  10. #10
    Forum Contributor
    Join Date
    06-16-2011
    Location
    London
    MS-Off Ver
    Excel XP
    Posts
    276

    Re: Class module / multidimensional array?

    I'm still trying to decipher yours.... :-)

  11. #11
    Forum Contributor
    Join Date
    06-16-2011
    Location
    London
    MS-Off Ver
    Excel XP
    Posts
    276

    Re: Class module / multidimensional array?

    Think I've cracked it.....I had the Class module definitions completely screwed up. Should be:

    Please Login or Register  to view this content.

  12. #12
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Class module / multidimensional array?

    With mine, unless I've missed something (proably )

    class cEngineer:
    Please Login or Register  to view this content.
    Then:
    Please Login or Register  to view this content.

  13. #13
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Class module / multidimensional array?

    Though this would be faster for a lot of data:
    Please Login or Register  to view this content.
    But I reckon a pivot table would be even quicker

  14. #14
    Forum Contributor
    Join Date
    06-16-2011
    Location
    London
    MS-Off Ver
    Excel XP
    Posts
    276

    Re: Class module / multidimensional array?

    I bow to your superior knowledge....but since I don't understand pivot tables either I'll stick with what works and move on to the next thing I don't understand.

  15. #15
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Class module / multidimensional array?

    Have a look at the attached. I reckon that there's a case for saying that pivot tables are the single most useful tool that Excel provides - once you suss them, you'll wonder how you ever did anything without them
    Attached Files Attached Files
    Last edited by Kyle123; 07-09-2013 at 09:36 AM.

+ 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