+ Reply to Thread
Results 1 to 26 of 26

Collection inside a class, issues retrieving data

  1. #1
    Registered User
    Join Date
    12-09-2014
    Location
    Norfolk
    MS-Off Ver
    2013
    Posts
    19

    Question Collection inside a class, issues retrieving data

    Hi guy's, im having issues extracting data from a collection inside a class modual. I have put the class into a collection and i can extract information from there, but i wanna know what ive done wrong as i cant get a reference from the class itself.
    I think the issue is coming from this class modual below, when call .item(1) i dont get .sscc, i have over looked something but im not sure what for the life of me



    Please Login or Register  to view this content.



    Please Login or Register  to view this content.



    Please Login or Register  to view this content.

    any ideas???? to point me in the right direction
    Last edited by bennett4455; 07-21-2015 at 05:43 AM. Reason: code tags

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

    Re: Collection inside a class, issues retrieving data

    Please use code tags, thems the rules. Until you do so we can't help. However as a pointer, since you're new are you returning the same thing from your item property in cls as cls2?

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

  3. #3
    Registered User
    Join Date
    12-09-2014
    Location
    Norfolk
    MS-Off Ver
    2013
    Posts
    19

    Re: Collection inside a class, issues retrieving data

    sorry about that ive edited it now, yes i am looking for the same item() from both.
    original cls has a collection and some other stuff, the second cls2 is just a custom collection class holding the original cls.
    I have done something wrong in the original cls coz the insistence doesn't work on .item(1). but does mycls2.item(mycls2.count).pSSCC.item(1) ?? im all out of ideas and would greatly appreciate a point in the right direction


    path is cls2......cls......collection.item()
    i want to get to cls.collection before i add it to cls2
    and it is a string input, large numbers really but integer and long cut off 0's at the end sometimes so using a string sorts this out

    hope this is enough information, also running windows 8.1 and excel 2013 not that it will make much difference lol
    Last edited by bennett4455; 07-21-2015 at 06:23 AM. Reason: more detail

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

    Re: Collection inside a class, issues retrieving data

    But you aren't returning a collection here;
    Please Login or Register  to view this content.
    You're returning an element from a collection, so it should really be:
    Please Login or Register  to view this content.
    Since all you're really putting into the collection is a string. Does that make sense?

  5. #5
    Registered User
    Join Date
    12-09-2014
    Location
    Norfolk
    MS-Off Ver
    2013
    Posts
    19

    Re: Collection inside a class, issues retrieving data

    Hi, yes it does make sense, i have already tried this but i still had no joy?

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

    Re: Collection inside a class, issues retrieving data

    Ok, start at the beginning. Your code doesn't make a huge amount of sense.

    In non coding layman's terms, what are you actually trying to do? What's the goal of this exercise?

  7. #7
    Registered User
    Join Date
    12-09-2014
    Location
    Norfolk
    MS-Off Ver
    2013
    Posts
    19

    Re: Collection inside a class, issues retrieving data

    Ok goal is step one, input data into a cls modual,name as string, Id as string then a sscc collection, at this point I can't get .item. Step 2 is put that cls into a collection. Does that make it clearer ?

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

    Re: Collection inside a class, issues retrieving data

    No, forget about how you want to do it, pretend classes don't exist.

    Pretend I don't know any programming, what are you trying to do. Presumably you have a workbook with some data in and you're trying to put this into data structure to do what?

  9. #9
    Registered User
    Join Date
    12-09-2014
    Location
    Norfolk
    MS-Off Ver
    2013
    Posts
    19

    Re: Collection inside a class, issues retrieving data

    Ok a product has a name, Id and multiple sscc's or sometimes none associated with it. I want to be able to get hold of all the products within my code at times, also find product with no sscc associated with it before deciding if I should add it to the list of all products or not

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

    Re: Collection inside a class, issues retrieving data

    So you want 2 things?

    1. You want a list of all Products and their SSCS numbers
    2. A list of selected products that you add to from the list of All Products

    Is that correct?

    Do you have a sample workbook with the data in?

  11. #11
    Registered User
    Join Date
    12-09-2014
    Location
    Norfolk
    MS-Off Ver
    2013
    Posts
    19

    Re: Collection inside a class, issues retrieving data

    Yes, I am currently on my phone, will send an example when I get back 2 my computer. Thanks for your patience lol

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

    Re: Collection inside a class, issues retrieving data

    Ok mate, I'll have a look

    Edit: Are you also trying to create custom collection classes or are you getting confused?
    Last edited by Kyle123; 07-21-2015 at 08:23 AM.

  13. #13
    Registered User
    Join Date
    12-09-2014
    Location
    Norfolk
    MS-Off Ver
    2013
    Posts
    19

    Re: Collection inside a class, issues retrieving data

    workbook is 2 big??? advice

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

    Re: Collection inside a class, issues retrieving data

    Smaller sample workbook?

  15. #15
    Registered User
    Join Date
    12-09-2014
    Location
    Norfolk
    MS-Off Ver
    2013
    Posts
    19

    Re: Collection inside a class, issues retrieving data

    have a butchers, it should all make sense now
    Attached Files Attached Files

  16. #16
    Registered User
    Join Date
    12-09-2014
    Location
    Norfolk
    MS-Off Ver
    2013
    Posts
    19

    Re: Collection inside a class, issues retrieving data

    Any education that could point me in the right direction

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

    Re: Collection inside a class, issues retrieving data

    How do you want to access the data? By SSCC, ID or Name?

    How should the structure for 1A003 look like, it each sscc seems to have quantities rather than the ID, wouldn't you therefore use sscc as the top level collection?

  18. #18
    Registered User
    Join Date
    12-09-2014
    Location
    Norfolk
    MS-Off Ver
    2013
    Posts
    19

    Re: Collection inside a class, issues retrieving data

    I would like to access the sscc. You are right in a way, the sscc does reference a quantity, it is an item with a unique code attached so u could use it as a count, but I want to get a reference to it from the Id

  19. #19
    Registered User
    Join Date
    12-09-2014
    Location
    Norfolk
    MS-Off Ver
    2013
    Posts
    19

    Re: Collection inside a class, issues retrieving data

    Basically what i need is
    MsgBox myStock.item(1).SSCC to work and
    myStock.remove(1).SSCC
    the rest i can sort out, cheers
    Last edited by bennett4455; 07-22-2015 at 01:56 PM. Reason: update

  20. #20
    Registered User
    Join Date
    12-09-2014
    Location
    Norfolk
    MS-Off Ver
    2013
    Posts
    19

    Re: Collection inside a class, issues retrieving data

    I've figured out a work round but i still dont understand why .item().sscc wont work
    Thanks to the guys who have had a look, much appreciated
    work round is

    Please Login or Register  to view this content.

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

    Re: Collection inside a class, issues retrieving data

    Because item doesn't return an object, you don't create an object. You just add a string to a collection and try and return an object, but it's not an object, it's a string.

    You haven't actually created an sscc object anywhere, if you want that then you meet to initialise that in our add method.

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

    Re: Collection inside a class, issues retrieving data

    I'll post you some code tomorrow when I'm at work.

    You haven't answered my question around how bothered you are about returning custom collections

  23. #23
    Registered User
    Join Date
    12-09-2014
    Location
    Norfolk
    MS-Off Ver
    2013
    Posts
    19

    Re: Collection inside a class, issues retrieving data

    what a plum, penny has just dropped lol, i feel so stupid now. its the set item = lol
    this is what u mean
    Thanks for shaking me, im all sorted now thanks a million

    Please Login or Register  to view this content.

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

    Re: Collection inside a class, issues retrieving data

    Yes, that's what I meant

  25. #25
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Collection inside a class, issues retrieving data

    My general solution is to declare Item as a Public collection
    i.e.
    Insead of
    Please Login or Register  to view this content.
    Use
    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  26. #26
    Registered User
    Join Date
    12-09-2014
    Location
    Norfolk
    MS-Off Ver
    2013
    Posts
    19

    Re: Collection inside a class, issues retrieving data

    Thanks a lot guys, how do I Mark this as resolved?

+ 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. Class and one property is also a class or collection
    By gosa in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-01-2011, 05:31 PM
  2. Replies: 22
    Last Post: 12-15-2010, 08:49 PM
  3. Collection of Class Modules
    By wildjester in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-11-2009, 09:26 AM
  4. Issues retrieving data from external sources
    By jschell in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-19-2009, 09:09 AM
  5. Class with property as collection of another class
    By MCCCLXXXV in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 11-26-2008, 04:35 PM
  6. [SOLVED] RE: Retrieving the Collection of Ranges in a Workbook
    By K Dales in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-19-2005, 06:06 PM
  7. [SOLVED] Retrieving the Collection of Ranges in a Workbook
    By Adam in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-19-2005, 06:06 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