From: Alexandros Peropulous on
My decision tree is organised as a class right now.
Is there a way to save a class to a file? Sounds impossible to me.
I tried it with a Put and Get statement, but that gave me a Type
Mismatch error.

Greetings
Alex
From: ralph on
On Fri, 23 Jul 2010 20:06:42 +0200, Alexandros Peropulous
<peropero(a)gmail.com> wrote:

>My decision tree is organised as a class right now.
>Is there a way to save a class to a file? Sounds impossible to me.
>I tried it with a Put and Get statement, but that gave me a Type
>Mismatch error.
>

Converting an object (or data structure) into a series of values for
storage, and the process for 're-converting' the storage back into an
object is called Serialization.
http://en.wikipedia.org/wiki/Serialization

VB provides no native support for serialization. So you need to write
your own, which isn't that difficult. It is pretty much boilerplate -
which is why so many OPLs do natively support serialization.

A class is merely instructions for creating an object. It defines the
attributes (data) and behavior (methods). At it simplest level just
define a data structure to package the attributes and provide method/s
to create or receive it.

[Warning! Simple psuedocode follows ...]
For example,
A simple class that packages its data into a comma-delimited
string.
' class A
Long lJunk
String sJunk
FromString( csvString )
ToString() As String
' end class

In code ...
' fetch
Open file
s = Get String
Set obj = New CSomeObject
obj.FromString s
' you now have a new CSomeObject
' save
Open file
Save obj.ToString
....

-ralph


From: Larry Serflaten on

"Alexandros Peropulous" <peropero(a)gmail.com> wrote
> My decision tree is organised as a class right now.
> Is there a way to save a class to a file? Sounds impossible to me.
> I tried it with a Put and Get statement, but that gave me a Type
> Mismatch error.

You have to convert your class' data to serial form (a string, or an array)
and save that to disk. When you read that back in, you have to
convert the serial form back into class data.

There are different ways to do that, but the conversion is left up
to you to do. VB does not provide a generic way to convert your
objects for you.

LFS


From: Larry Serflaten on

"ralph" <nt_consulting64(a)yahoo.net> wrote

> [Warning! Simple psuedocode follows ...]
> For example,
> A simple class that packages its data into a comma-delimited
> string.
> ' class A
> Long lJunk
> String sJunk
> FromString( csvString )
> ToString() As String
> ' end class


Some objects provide a Clone function that returns a duplicate
copy of the object. For serialization I often recommend using a
Copy property:


Public Property Get Copy() As String
' code to serialize class data
End Property

Public Property Let Copy(Data As String)
' code to de-serialize class data
End Property


I just think that provides for better syntax. Compare the
different syntax needed to create a clone:

' Clone
Set bb = aa.Clone()

' To/From string
Set bb = New class
bb.FromString(aa.ToString)

' Copy
Set bb = New class
bb.Copy = aa.Copy


Just another 2�
LFS


From: ralph on
On Fri, 23 Jul 2010 17:34:10 -0500, "Larry Serflaten"
<serflaten(a)gmail.com> wrote:

>
>Some objects provide a Clone function that returns a duplicate
>copy of the object. For serialization I often recommend using a
>Copy property:
>
>
> Public Property Get Copy() As String
> ' code to serialize class data
> End Property
>
> Public Property Let Copy(Data As String)
> ' code to de-serialize class data
> End Property
>
>
>I just think that provides for better syntax. Compare the
>different syntax needed to create a clone:
>
>' Clone
>Set bb = aa.Clone()
>
>' To/From string
>Set bb = New class
>bb.FromString(aa.ToString)
>
>' Copy
>Set bb = New class
>bb.Copy = aa.Copy
>
>
>Just another 2�
>LFS
>

Copying or Clone making, and Serialization are related as they are
processes for managing an object's attributes for either immediate or
delayed creation of a 'new' object, but IMHO are subtly different and
semantically best managed separately. Cloning for example, can lead to
Prototype or Factory designs.
[Although I have no disagreement with your scheme. What ever works.]

Based on what little I know of the OP's needs I would probably adopt a
scheme similar to the ADODB.Recordset and encapsulate the entire i/o
within the object.
MyObject.Save "full_filename_path", ccPersistCVS | ccPersistXML
....
or any other location or format that might be useful

Then to retrieve
Set MyObject = New CMyObject
MyObject.Open "full_filename_path"

I suspect that you put 5 programmers in a room you would come up with
6 possible solutions. <g>

-ralph