Results 1 to 16 of 16

Thread: What is Serialization? [Resolved]

Threaded View

  1. #10
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    Sorry, I neglected to supply you with means of loading the file back into the object!

    VB Code:
    1. Shared Function FromFile(ByVal path As String) As !!YOUR_CLASS_NAME_HERE!!
    2.     'this method returns an object loaded from the file specified by path
    3.     'if the file path doesn't exist then a new object is created and returned
    4.  
    5.     Dim temp As !!YOUR_CLASS_NAME_HERE!!
    6.  
    7.     If File.Exists(path) Then
    8.  
    9.         Dim binser As BinaryFormatter
    10.         Dim input As Stream
    11.  
    12.         Try
    13.             'load the file
    14.             binser = New BinaryFormatter   
    15.             input = New FileStream(path, FileMode.Open, FileAccess.Read, FileShare.None)            'open the file
    16.             temp = CType(binser.Deserialize(input), !!YOUR_CLASS_NAME_HERE!!)              'extract instance from stream
    17.             input.Close()
    18.  
    19.         Catch ex As Exception
    20.             If Not IsNothing(input) Then input.Close()
    21.             temp = Nothing
    22.             Return Nothing
    23.         End Try
    24.     Else
    25.         temp = New !!YOUR_CLASS_NAME_HERE!!
    26.         temp.Path = path
    27.     End If
    28.  
    29.     Return temp
    30.  
    31. End Function

    It is a shared function.

    so you would use...
    VB Code:
    1. dim x as MyClass = MyClass.FromFile("Path")
    ...to call it.
    Last edited by wossname; Jun 2nd, 2004 at 07:49 AM.
    I don't live here any more.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width