Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

I'm having some trouble serializing textboxes here is the code:

Edit: never mind I got it to work, this is the code if anyone wants to serialize textboxes:

 

Class Save:

<Serializable()> Public Class Save
   Public FirstName As String '= "Name" ' I cut out this part
   Public LastName As String '= "email" ' and this
   Public email As String '= "email" ' and this to make it work :)
End Class

Other Code:

Private Ser As New Save

Imports System.Runtime.Serialization.Formatters.Binary 
Imports System.Xml.Serialization

Serializing:

    Private Sub Form1_Closing(ByVal sender As System.Object, ByVal e As _
   System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
       Ser.FirstName = CType(TextBox2.Text, String)
       Ser.LastName = CType(TextBox3.Text, String)
       Ser.Email = CType(TextBox4.Text, String)

       Dim myFileStream As Stream = File.Create("Save.bin")
       Dim serializer As New BinaryFormatter
       serializer.Serialize(myFileStream, Ser)
       myFileStream.Close()
   End Sub

 

Deserializing:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       If File.Exists("Save.bin") Then
           Dim myFileStream As Stream = File.OpenRead("Save.bin")
           Dim deserializer As New BinaryFormatter
           Ser = CType(deserializer.Deserialize(myFileStream), _
       Save)
           myFileStream.Close()
       End If
       TextBox2.Text = Ser.FirstName
       TextBox3.Text = Ser.LastName
       TextBox4.Text = Ser.email
   End Sub

Edited by decrypt

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...