![]() |
Object Serialisation
Hi there, can anyone please guide me on how to do object serialisation
in VBA? Many Thanks Lloyd |
Object Serialisation
sorry but i can't understand what's object serialization.
could you explain it more in detail? sorry again for not helping you -- msn --------------------------------------------- the best time to plant a tree was twenty years ago. the second best time, is today - Chinese proverb "pinkfloydfan" wrote: Hi there, can anyone please guide me on how to do object serialisation in VBA? Many Thanks Lloyd |
Object Serialisation
http://en.wikipedia.org/wiki/Serialization
-- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "timebird" wrote in message ... sorry but i can't understand what's object serialization. could you explain it more in detail? sorry again for not helping you -- msn --------------------------------------------- the best time to plant a tree was twenty years ago. the second best time, is today - Chinese proverb "pinkfloydfan" wrote: Hi there, can anyone please guide me on how to do object serialisation in VBA? Many Thanks Lloyd |
Object Serialisation
Timebird
I understand that serialization is the process whereby you store an object on a hard drive in some readable format that it can be loaded back in again should you so wish. It would be very useful to me to know how to do this in VBA as I have some pretty complicated objects that are somewhat memory intensive and so would like to be able to store them permanently outside of RAM so I don't have to keep re-creating them every time I open my application. Thanks Lloyd |
Object Serialisation
If I understand, what you need to save is the data the VBA routine needs to
recreate an object from its class. This may be as simple as a text file with a list of property names and corresponding values, which are saved and loaded by the object or the code controlling the object. The code will have to be able to distinguish from creating a new object of the class and recreating a previously defined instance of the class. - Jon ------- Jon Peltier, Microsoft Excel MVP Tutorials and Custom Solutions http://PeltierTech.com _______ "pinkfloydfan" wrote in message oups.com... Timebird I understand that serialization is the process whereby you store an object on a hard drive in some readable format that it can be loaded back in again should you so wish. It would be very useful to me to know how to do this in VBA as I have some pretty complicated objects that are somewhat memory intensive and so would like to be able to store them permanently outside of RAM so I don't have to keep re-creating them every time I open my application. Thanks Lloyd |
Object Serialisation
That sounds about right Jon
I think what I need is two additional methods (SerialiseObject & UnserialiseObject): running the SerialiseObject method stores the raw object data in a text file and conversely the UnserialiseObject method loads the data back (either into an existing object or a new one). So, can you give me some pointers on how to do that please? Thanks a lot Lloyd |
Object Serialisation
Maybe think about using XML or some other structured type of text file.
What part do you need help with? Can you write/read a text file? Can your objects be serialized to text? This is not always straightforward: for example your object may have a property which refers to another object (a custom object or a workbook for example): this would not be trivial to persist to a file. Maybe you could describe the type of object you want to serialize ? Tim "pinkfloydfan" wrote in message oups.com... That sounds about right Jon I think what I need is two additional methods (SerialiseObject & UnserialiseObject): running the SerialiseObject method stores the raw object data in a text file and conversely the UnserialiseObject method loads the data back (either into an existing object or a new one). So, can you give me some pointers on how to do that please? Thanks a lot Lloyd |
Object Serialisation
Thanks for the input Tim
Unfortunately, I am only familiar with VBA and don't have any knowledge of other programming languages at this time. The specific object I want to serialise has some simple core data that it uses to create a path-dependent result. I store every step of the path in an array and it not unusual to have between 250-1250 steps for a single object. This process is then repeated many thousands of times and all these objects are stored in a master object / collection. You can appreciate that I don't really want to wait a few minutes to build the master object(s) each time I use my application and so was looking for a way to store that data outside of Excel and re-load it as I need it. Actually if this can be achieved efficiently I can think of a lot of uses for this process. Perhaps if anyone can guide me on how to write an object's properties to a text file and read them back in that would be a good place to start...or is there a more efficient method? Many Thanks Lloyd |
Object Serialisation
If the contents of an array can be repesented as text then you could use
join() to convert the array into a text string and then write it to a text file. Plenty of examples of wrting to a file to be had by searching this newsgroup, so no need for me to repeat any of them here. Or if you want something more structured then use an xml representation <propertyname1 <valvalue1</val <valvalue2</val .... <valvalueX</val </propertyname1 <propertyname2 ...... </propertyname2 etc. or write the values to an Excel sheet and use that as your cache. You might want to investigate speeding up your object-building code though. If the objects are built without a lot of user-input then it might be quicker just to rebuild them from scratch. Tim "pinkfloydfan" wrote in message oups.com... Thanks for the input Tim Unfortunately, I am only familiar with VBA and don't have any knowledge of other programming languages at this time. The specific object I want to serialise has some simple core data that it uses to create a path-dependent result. I store every step of the path in an array and it not unusual to have between 250-1250 steps for a single object. This process is then repeated many thousands of times and all these objects are stored in a master object / collection. You can appreciate that I don't really want to wait a few minutes to build the master object(s) each time I use my application and so was looking for a way to store that data outside of Excel and re-load it as I need it. Actually if this can be achieved efficiently I can think of a lot of uses for this process. Perhaps if anyone can guide me on how to write an object's properties to a text file and read them back in that would be a good place to start...or is there a more efficient method? Many Thanks Lloyd |
Object Serialisation
Ok Tim, thanks for your time, I think I have enough pointers to get me
started here |
Object Serialisation
One of the easiest ways to store arrays is in an Excel worksheet. Loading a
large workbook takes a few seconds, but you can move arrays between the sheet and VBA quickly, then processing the arrays in VBA is pretty fast. ' move data from Excel range to VBA array: Dim vArrayInput As Variant vArrayInput = Workbooks("Book1.xls").Worksheets("Sheet2").Range( "C3:Q504").Value ' move data from VBA array to Excel range: Dim vArrayOutput(RowMin To RowMax, ColMin To ColMax) As Variant ' or other type ' populate vArrayOutput (not shown: do it according to your app) Workbooks("Book3.xls").Worksheets("Sheet4").Range( "X200") _ .Resize(UBound(vArrayOutput,1) + 1 - LBound(vArrayOutput,1), _ UBound(vArrayOutput,2) + 1 - LBound(vArrayOutput,2)).Value = vArrayOutput - Jon ------- Jon Peltier, Microsoft Excel MVP Tutorials and Custom Solutions http://PeltierTech.com _______ "pinkfloydfan" wrote in message oups.com... Thanks for the input Tim Unfortunately, I am only familiar with VBA and don't have any knowledge of other programming languages at this time. The specific object I want to serialise has some simple core data that it uses to create a path-dependent result. I store every step of the path in an array and it not unusual to have between 250-1250 steps for a single object. This process is then repeated many thousands of times and all these objects are stored in a master object / collection. You can appreciate that I don't really want to wait a few minutes to build the master object(s) each time I use my application and so was looking for a way to store that data outside of Excel and re-load it as I need it. Actually if this can be achieved efficiently I can think of a lot of uses for this process. Perhaps if anyone can guide me on how to write an object's properties to a text file and read them back in that would be a good place to start...or is there a more efficient method? Many Thanks Lloyd |
Object Serialisation
Thanks Jon, that's an excellent idea.
Unfortunately, in this case it won't do as the arrays would be greater than the size of the spreadsheet which leaves me having to split them and work across more than one worksheet. Instead, I'm looking into creating a structured text file which includes some form of identifier/header for each property of each object. I am hoping that I will then be able to load the object back by going to each identifier in the text file and reading in the next [line] of text. I wonder if anybody else has ever done this before? Lloyd |
All times are GMT +1. The time now is 07:33 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com