Example Class
<Serializable()> Public Class Contact Private mForename As String = "" Public Property Forename() As String Get Return mForename End Get Set(ByVal value As String) mForename = value End Set End Property Private mSurname As String = "" Public Property Surname() As String Get Return mSurname End Get Set(ByVal value As String) mSurname = value End Set End Property Private mState As String = "" Public Property State() As String Get Return mState End Get Set(ByVal value As String) mState = value End Set End Property Private mContactDate As DateTime = #1/1/2000# Public Property ContactDate() As DateTime Get Return mContactDate End Get Set(ByVal value As DateTime) mContactDate = value End Set End Property Private mAddress As String = "" Public Property Address() As String Get Return mAddress End Get Set(ByVal value As String) mAddress = value End Set End Property Private mCity As String = "" Public Property City() As String Get Return mCity End Get Set(ByVal value As String) mCity = value End Set End Property Private mZipCode As String = "" Public Property ZipCode() As String Get Return mZipCode End Get Set(ByVal value As String) mZipCode = value End Set End Property Private mComments As String = "" Public Property Comments() As String Get Return mComments End Get Set(ByVal value As String) mComments = value End Set End Property End Class
This the defunct way of save objects.
Microsoft.VisualBasic.FileSystem.FilePutObject(Of FileNumber, Object)
This is the .net way
Public Roladex As New List(Of Contact)
To Save
Dim F As Runtime.Serialization.Formatters.Binary.BinaryFormatter
Dim s As IO.Stream
F = New Runtime.Serialization.Formatters.Binary.BinaryFormatter()
s = New IO.FileStream("FileName.bin", IO.FileMode.Create, IO.FileAccess.Write, IO.FileShare.None)
F.Serialize(s, Roladex)
s.Close()
To Load
Dim f As Runtime.Serialization.Formatters.Binary.BinaryFormatter
Dim s As IO.Stream
f = New Runtime.Serialization.Formatters.Binary.BinaryFormatter()
s = New IO.FileStream("FileName.bin", IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.None)
Roladex = DirectCast(f.Deserialize(s), Object)
s.Close()
Now you save objects serialization-ninja style






MultiQuote


|