April 6th, 2013, 06:18 AM
How to save a project to a file.
I am currently on a project where I need to implement a function so the user can save their session. What's the best way to do that if you have a couple of objects of classes and som arraylists.
Is XML the way to go? I have tried doing it with XML and it worked with one object but not with more.
I would be really happy if you could demonstrate with the code below since that would show the concept in a easy way.(I want it to function like this: The first time you start the program you click on the button and all objects gets their values. Then everything is saved/serialized into perhaps an XML file. The next time you start you should be able to retrieve the values from the file instead.
Public Class Form1
Public class1Object As New Class1
Public class2Object As New Class2
Public listTest As New ArrayList
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Gives values to the variables in the objects.
class1Object.Variable1 = 50
class1Object.Variable2 = "Test"
class2Object.Variable3 = 100
class2Object.Variable4 = "Test2"
Public Class Class1
Public Variable1 As Integer
Public Variable2 As String
Public Class Class2
Public Variable3 As Double
Public Variable4 As String