decrypt Posted January 3, 2004 Posted January 3, 2004 (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 SaveImports 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 January 3, 2004 by decrypt Quote
Administrators PlausiblyDamp Posted January 3, 2004 Administrators Posted January 3, 2004 Just curious as to why are you using CType to convert strings to strings in the serializing bit. The .Text properties are already a string. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
decrypt Posted January 3, 2004 Author Posted January 3, 2004 oh, I never knew that, i must have forgotten :P It doesn't really matter though :P Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.