467,879 Members | 1,087 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,879 developers. It's quick & easy.

VB2005 Class Issue

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
  • viewed: 1363
Share:
1 Reply
1GB
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.

Similar topics

4 posts views Thread by Roger Allen | last post: by
2 posts views Thread by Jordi Juliŗ | last post: by
7 posts views Thread by TAVOSOFT | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.