Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Collections of Collections

Status
Not open for further replies.

RobertMottram

Programmer
Apr 25, 2002
39
GB
I am new to using Class Modules and I am trying to create a collection of a collection (or I think this is the right way!)
I am trying to write an interface to run reports. I am creating a clase module to try and make things simplar in the program (as I am getting confused what everything it.
I have a class modules with a collection of REPORTS. This contains information about each report, ie filelocation, reportname etc. what I now want to add is a set of PARAMETERS. These are parameters which can be set to the report to change the selection statment of the report. Each parameter needs a number of bit of information, including Parametername, DataType, ParameterInReport etc.
The way I was trying to do this was create a collection of the report collection, but I am have trouble doing this. I was hoping some one might be able to help me. I would like to have a situation where I could have a line like this.
Code:
CurrentParamName = ReportList.Report(1).Parameter(1).Name
So I could then be able to pull any parameter for any report. The main problem is I am unsure how the create the second collection so it will create a collection for each report in the REPORT collection

Thanks for any help you could give

Rob
 
Why not just make a class for the report and set all the parameters for that specific report. This way each instance of the class would be a seperate report. Then you could use another class module to make a collection of your report class (a class collection) or is that what you mean? Anything is possible, the problem is I only have one lifetime.
[cheers]
 
That is exactly what I wanted, just not yet go the best grasp of Clase Modules and Collections, but I am getting there!
Do you know any good web sites or resources which I may be able to look at which might give me some information on Clase Modules and collections as I am sure I will find other problems but have not managed to find any good resources to help me yet as I don't really want to ask here everytime I have a small problem. (But the help is always very good, so I try not to waste peoples time until I have looked else where)

Thanks very much for that

Rob
 
Francesco Balena's Programming Microsoft Visual Basic 6.0 which is available at covers collection of classes in detail and is a great reference for all things VB. Microsoft's MSDN has all sorts of info as well.
Hope this at least gives you a good starting point. If you would like I can give you a brief overview of the Class/Collection thing. Anything is possible, the problem is I only have one lifetime.
[cheers]
 
A brief Overview of the Class/Collection thing would be great at some point if you get time.

Thanks very much

Rob
 
This is just an overview not a detailed explaination. A collection is a structure that works like an array and stores related items. A collection is an object and therefore have properties and methods. The main advantage of a collection over an array is that you can access an item in a collection via a key. For example if you made an array of city names and the city population you would need to know the index to get the population element from the array. If you make a collection of cities and use the name of the city as the key and then call the population item buy using the name of the desired city. This also eleminants(usually) the need to maintain the order of the items. If you remove the city population at index 12 you need to remember that with an array but you don't need to worry about it with a collection. Again this is just a brief description not a full tutoral.
The class module is a method of building and object. An object being a piece of self maintained information. For example you could make a class module for a person. This person "object" would have certain properties such as a first name, last name, height, weight, etc. With the person class you can expose and verify the properties that you wish to the outside program. For example you could restrict the weight property to ensure that it was valid by being both a number and that it was a positive number. By doing this it helps you the class developer restrict abuse of the person object and points you in the direction of developing "robust" "object orientated" code. Another aspect of the class module for the person "object" would allow you to create a method of the class. For example you could create a "Full Name" method that would merge the first name and the last name of the person. This allows you to once again regulate the data of the person class. By making this a method you could regulate the full name returned by the method to be some combination of names intials, and punctuation there by restricting the outside program to only be able to use the combinations you wish. This is the foundation for object orientated programming, self contained self maintained robust code.
A collection there for becomes a great way to maintain a group of similar objects (person class) hence the concept of a "Collection of Classes" which you would make by creating another class module which would use you person class and become a collection class. Confused Yet? The whole concept takes time to sink in, as I am sure there will be people who will read this and have additional comments and or differences of ideas and explainations. The bottom line is it will come in time and you have accessed a great wealth of information with this website. There is no such thing as a dumb question as some one on this website might have to decypher your code someday. Hope this helps and good luck. Anything is possible, the problem is I only have one lifetime.
[cheers]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top