Hello,
I am making a program that has faily a lot of variables. most of them are string,
but I have some date formats and string formats... I am not done with the app,
so I am not sure completely what data I need to save, but for now, let's say,
Date
String (Some may be multilines)
Double ( A LOT of these)
and for each variable, I need to assign the correct data that I saved...
and for each variable, I need to load the right variable with the correct type for each variable. I mean it would be bogus to save "13" as an integer but load it as date...
and save date but load it as string, and everything gets mixed up!
I am a newbie that just uses newb programming, but it's only for school (Although a fast reply would be great... I've got the whole summer to work this whole thing out.
but I need to be able to save...
if anyone has a simple idea, that would be greatful to my knowledge and
the program!
Please let me get started!
Thank You
Keehun Nam

Saving File Format Idea... Help me
floris_olivier
Hi Keehun,
If you want to save all the data in one object (let's say of type AppData), I would suggest using .NET Serialization. The root topic is at http://msdn2.microsoft.com/en-us/library/7ay27kt9(VS.80).aspx. My sample code is based on this topic http://msdn2.microsoft.com/en-us/library/szzyf24s(VS.80).aspx and http://msdn2.microsoft.com/en-us/library/fa420a9y(VS.80).aspx.
Define your application data
<Serializable()> _
Public Class AppData
Public dates As DateTime()
Public lines As String()
Public numbers As Double()
End Class
Serialize it
' Populate the data
Dim myData As New AppData
Dim date1 As DateTime = DateTime.Now
Dim date2 As DateTime
DateTime.TryParse("2006-04-03", date2)
myData.dates = New DateTime() {date1, date2}
myData.lines = New String() {"First line", _
"Second line " & Environment.NewLine & "with line break", "Third line"}
myData.numbers = New Double() {1.2, 3.4, 5.6}
' Serialize it
Dim xmlSerializer As New System.Xml.Serialization.XmlSerializer(GetType(AppData))
Dim streamWriter As New System.IO.StreamWriter("Test.xml")
xmlSerializer.Serialize(streamWriter, myData)
streamWriter.Close()
Deserialize it
Dim xmlSerializer As New System.Xml.Serialization.XmlSerializer(GetType(AppData))
Dim streamReader As New System.IO.StreamReader("Test.xml")
Dim myReadData As AppData = TryCast(xmlSerializer.Deserialize(streamReader), AppData)
streamReader.Close()
Best regards,