By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,554 Members | 1,146 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,554 IT Pros & Developers. It's quick & easy.

VB2005 Class Issue

P: 3
Problem:
I wanted to implement what I did in VB6 where I would use a global structure and dimension an array of structures then the program could load data into it at start up. Global routines would be able access the data whenever required and save any changes. Since it isn't a lot of data, I don't want the overhead of a dbms.

With VB2005 (express) I created a class that consisted essentially of one record of the previous structure. Now I have 2 problems:
How do I create a number of instances of the class where I can access all the properties and methods?
How can the rest of the program access the data since I have to instantiate the class in another class (such as a form)?

Solutions?:
Can I create an array of global objects with certain methods shared between objects for loading/saving and other common tasks (I think this can be accomplished with the Shared keyword)

Or
Would it be better for the objects to be created/destroyed as needed with the common methods (such as load/save etc.) available at all times (through the Shared keyword). Then the data would be read and written to disk when interacting with the objects. In effect disk storage, rather than RAM storage would make the data globally available to the program.

Or
Would it work and perhaps be better just to create an array of a structure inside the class so all the data is encapsulated inside the class and then use #2 above (except only one instance of the class need be instantiated (and thus, no methods would need to be shared))

Any help would be appreciated--trying to make the conceptual leap to OOP
Nov 13 '06 #1
Share this Question
Share on Google+
1 Reply


100+
P: 1,646
Problem:
I wanted to implement what I did in VB6 where I would use a global structure and dimension an array of structures then the program could load data into it at start up. Global routines would be able access the data whenever required and save any changes. Since it isn't a lot of data, I don't want the overhead of a dbms.

With VB2005 (express) I created a class that consisted essentially of one record of the previous structure. Now I have 2 problems:
How do I create a number of instances of the class where I can access all the properties and methods?
How can the rest of the program access the data since I have to instantiate the class in another class (such as a form)?

Solutions?:
Can I create an array of global objects with certain methods shared between objects for loading/saving and other common tasks (I think this can be accomplished with the Shared keyword)

Or
Would it be better for the objects to be created/destroyed as needed with the common methods (such as load/save etc.) available at all times (through the Shared keyword). Then the data would be read and written to disk when interacting with the objects. In effect disk storage, rather than RAM storage would make the data globally available to the program.

Or
Would it work and perhaps be better just to create an array of a structure inside the class so all the data is encapsulated inside the class and then use #2 above (except only one instance of the class need be instantiated (and thus, no methods would need to be shared))

Any help would be appreciated--trying to make the conceptual leap to OOP
Hi. With OOP the methods of an object only appear once in memory while the data is stored separately for each object. You can treat the data in an object as if it were a data structure. Having 2 or more instantiations of the same object gives you twice the data and only one set of code.

It will probably be easier for you to create an array of this object and make the array global. Each element will, apparently, have it's own methods although they are always shared. Remove the structure and add the variables independently with propert get and let functions

arMyObjects(25).MyVariable = 1254 'property let
MsgBox "MyVariable = " & arMyObjects(25).MyVariable 'property get
Nov 13 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.