Results 1 to 15 of 15

Thread: Initialise Structure, Collection, Array

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Posts
    258

    Initialise Structure, Collection, Array

    I have a very large amount of data I want to load into a collection, array or similiar structure.

    I created a Module with a collection and just tried to add all the items when the routine was called, but this resulted in a:

    "Procedure too large" error message.

    What is the best approach to handle this?
    Ideally I'd like to do it at compile time, if that's an option with VB, which I'm not sure it is.

    Thanks in advance.

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,135

    Re: Initialise Structure, Collection, Array

    Quote Originally Posted by LucaUWF
    ...I created a Module with a collection and just tried to add all the items when the routine was called, but this resulted in a:

    "Procedure too large" error message. ...
    How did you do it? Can you give us some details or perhaps show us some code?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Posts
    258

    Re: Initialise Structure, Collection, Array

    Well, that's not really important as I'm sure there must be a better way in any case, but...

    I created a Collection and then added to that collection all my data.

    Several thousand strings, and hence lines of code - which caused the problem.

  4. #4
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,135

    Re: Initialise Structure, Collection, Array

    Quote Originally Posted by LucaUWF
    Well, that's not really important as I'm sure there must be a better way in any case, but...

    I created a Collection and then added to that collection all my data.

    Several thousand strings, and hence lines of code - which caused the problem.
    It is important to know HOW you do things if you want us to improve your coding techic(s). Sorry pal but that's the reality - without it no-one would be able to help you. We can suggest lots of things but non of them may be suitable for you. We need to know as much details as possible.

  5. #5
    Hyperactive Member
    Join Date
    Jun 2004
    Posts
    468

    Lightbulb Re: Initialise Structure, Collection, Array

    Quote Originally Posted by LucaUWF
    What is the best approach to handle this?
    Ideally I'd like to do it at compile time
    You could simply break the routine into several smaller ones:
    VB Code:
    1. Dim col As Collection
    2.  
    3. Public Sub Initialize()
    4.   Set col = New Collection
    5.   Init1
    6.   Init2
    7.   Init3
    8.   '...
    9. End Sub
    10.  
    11. Private Sub Init1()
    12.   col.Add "Item #1"
    13.   col.Add "Item #2"
    14.   col.Add "Item #3"
    15.   '...
    16. End Sub
    17.  
    18. Private Sub Init2()
    19.   col.Add "Item #101"
    20.   col.Add "Item #102"
    21.   col.Add "Item #103"
    22.   '...
    23. End Sub
    24.  
    25. Private Sub Init3()
    26.   col.Add "Item #201"
    27.   col.Add "Item #202"
    28.   col.Add "Item #203"
    29.   '...
    30. End Sub

  6. #6
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,135

    Re: Initialise Structure, Collection, Array

    Breaking into smaller procedure may help but cannot be (in this case) permanent solution - from my point of view, if you have tooooo many items to add to array/collection then it could be much better to store them all in the file or table and load it dynamically.

  7. #7
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Initialise Structure, Collection, Array

    "Proceedure Too Large" Usually means exactly what it states... You procedure contains too many lines of code. Proper coding techniques will eliminate this type of error.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Posts
    258

    Re: Initialise Structure, Collection, Array

    Randem, yes.... the error was pretty self explanatory - that's what I'm asking, how to code it in vb? Were it C, C++, C# no problem I'd create a constant structure.

    Rhino, I'm not doing anything special that's why I didn't post it, I'm just adding items to a collection... but there's sereval thousand items as I said, so that causes the problem. I currently read from a file, but that takes time and is what I'm trying to remove if possible.

    bpd, this is what I'm hoping to avoid, it's a little clunky.
    Last edited by LucaUWF; Apr 20th, 2006 at 04:41 AM.

  9. #9
    Hyperactive Member
    Join Date
    Jun 2004
    Posts
    468

    Re: Initialise Structure, Collection, Array

    Quote Originally Posted by LucaUWF
    bpd, this is what I'm hoping to avoid, it's a little clunky.
    Clunky? Hmmm, personally, I'd have thought that coding several thousand items would have been the clunky part.

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Posts
    258

    Re: Initialise Structure, Collection, Array

    No more so than it would be in any initialised structure, such as a central data table. The embedded product I'm working on at the minute has an internal database of several thousand items stored in FLASH.

    It's a speed thing really, it's quicker than loading from a file. :S

  11. #11
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Initialise Structure, Collection, Array

    LucaUWF,

    What do you mean "How to code it in VB"???? Make your procedure smaller.... Put some code in a sub routine and call it from the main procedure... I don't understand the confusion...

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Posts
    258

    Re: Initialise Structure, Collection, Array

    I just figure/hoped that there must be a better way. If there isn't then I guess I'm left with my original options.

  13. #13
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Initialise Structure, Collection, Array

    Better way of what???? You have posted no code so all we can do is guess at what you are even attempting to do or what your REAL problem is...

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Posts
    258

    Re: Initialise Structure, Collection, Array

    It's all covered in the posts above... but to clarify.

    I initially read all the data from a file, it was too slow.

    bpd, suggested doing what I had to resort to, splitting the long collection add routine into smaller ones to avoid the error - as before, I'll spare the pasting of reems of: col.add "items"

    I want to know IF there's a better way to load all the data than having to resort to adding data to a collection by calling an init (or several) routines. That's all, really.

  15. #15
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,501

    Re: Initialise Structure, Collection, Array

    It's all covered in the posts above
    Nope, you have only offered very vague hints - apart from the fact that at the moment you are using a collection.

    You haven't shown us the code you used to load from a file, or the code you use to store/load the data in code. Without that, we can only guess at the code you have.

    The chances are that if you show us a sample of your code (including how you use the data) and a small part of the data, we can suggest improvements (perhaps hundreds of times faster, depending on what you are doing).

Posting Permissions

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



Click Here to Expand Forum to Full Width