Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 196
  • Last Modified:

How can I assign "Me" reference from a class to a value?

I am trying to write a LoadFromFile() Sub that will deserialize a file from the HD into my class object, but I cant do it because " 'Me' cannot be target of an assignment ". Right now I am deserializing into a temporary object and then assigning member by memebr to the Me instance. Is thera a way around this?
Dim formatter As System.Runtime.Serialization.Formatters.Binary.BinaryFormatter = New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
        Dim output As FileStream
        Dim fileName As String = file.FullName
 
        Try
            output = New FileStream(fileName, FileMode.Open, FileAccess.Read)
            Dim tempCon As CConnectionData.CSettings
            tempCon = formatter.Deserialize(output)
            Me.m_szDatabase = tempCon.m_szDatabase
            Me.m_szLoginName = tempCon.m_szLoginName
            Me.m_szPassword = tempCon.m_szPassword
            Me.m_szSQLServer = tempCon.m_szSQLServer
            Me.m_nAuthenticationType = tempCon.m_nAuthenticationType
            output.Flush()
            output.Close()
        Catch ex As System.Runtime.Serialization.SerializationException
            Console.WriteLine("Error Reading from File. " & ex.Message)
        End Try

Open in new window

0
aferia
Asked:
aferia
1 Solution
 
Jaime OlivaresCommented:
to avoid this situation, you can invoke the deserialization class from outside an instance of your class, maybe form a static (Shared) sub, like:

Public Shared Sub Deserialize(filename as String) as CConnectionData.CSettings

     ... all your stuff here

End Sub
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now