Click here to Skip to main content
15,912,205 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: i modify row no 1 but change modify row no 10 ? Pin
Tom Deketelaere19-May-09 1:50
professionalTom Deketelaere19-May-09 1:50 
GeneralRe: i modify row no 1 but change modify row no 10 ? Pin
krrish95420-May-09 3:23
krrish95420-May-09 3:23 
QuestionRun application on windows start up Pin
hrishiS18-May-09 21:20
hrishiS18-May-09 21:20 
AnswerRe: Run application on windows start up Pin
~Khatri Mitesh~18-May-09 21:28
~Khatri Mitesh~18-May-09 21:28 
GeneralRe: Run application on windows start up Pin
hrishiS18-May-09 21:37
hrishiS18-May-09 21:37 
AnswerRe: Run application on windows start up Pin
MohammadAmiry19-May-09 1:19
MohammadAmiry19-May-09 1:19 
AnswerRe: Run application on windows start up Pin
Tom Deketelaere19-May-09 1:54
professionalTom Deketelaere19-May-09 1:54 
QuestionXML Serialization Pin
MrColeyted18-May-09 21:06
MrColeyted18-May-09 21:06 
Hello all. I am trying to write a simple program that defines a Car class and writes an XML Serialized Car object to an XML file. This is a Console app. Right now, I have the XMLSerializer Object defined and initialized with Module Scope. Within the main method, I create a filestream and a streamwriter that I pass to it to write the serialized Car object to the file. This works fine, but when I re-open the program after closing it, it cannot read the object back in once more than one have been written to the .xml file. I assume that this is because when a second object is written to the file, the xml header is re-inserted into the same file, and it is throwing the reader off. I have posted me code below.

I am trying to learn how to read and write XML with VB. Any help would be appreciated.


Imports System.Xml.Serialization
Imports System.IO

Public Module Module1
      Public xs As New Xml.Serialization.XmlSerializer(GetType(Car))
      Dim car1 As Car
      Dim car2 As Car
      <Serializable> Public Class Car
            Public Make As String
            Public Model As String
            Public Color As String
            Private year As Integer
            Public Property TheYear() As Integer
                  Get
                        Return year
                  End Get
                  Set(ByVal value As Integer)
                        year = value
                  End Set
            End Property
            Public Sub New()
                  Make = "Chevy"
                  Model = "Camero"
                  Color = "Tan"
                  year = 2003
            End Sub
      End Class
      Public Sub Main()
            Try
                  Dim fileName As String = "C:\\XMLCar.xml"
                  Dim f As New FileStream(fileName, FileMode.Append, FileAccess.Write)
                  Dim t As StreamWriter = New StreamWriter(f)

                  car1 = New Car()
                  xs.Serialize(t, car1)

                  t.Close()
                  Dim sr As New StreamReader(fileName)
                  car2 = xs.Deserialize(sr)

                  Console.WriteLine(car2.Model)
            Catch ex As Exception
                  Console.WriteLine(ex.Message)
            End Try
            Console.ReadKey()
      End Sub
End Module

"If you don't know where you're going, you'll probably end up somewhere else." Yogi Berra

AnswerRe: XML Serialization Pin
nlarson1119-May-09 5:00
nlarson1119-May-09 5:00 
GeneralRe: XML Serialization Pin
MrColeyted19-May-09 6:06
MrColeyted19-May-09 6:06 
GeneralRe: XML Serialization Pin
nlarson1119-May-09 7:41
nlarson1119-May-09 7:41 
QuestionDynamically Loading Image in Crystal Report Pin
Ovais Memon18-May-09 20:46
Ovais Memon18-May-09 20:46 
QuestionRandom Numbers Pin
GregoryWB18-May-09 15:08
GregoryWB18-May-09 15:08 
AnswerRe: Random Numbers Pin
_Damian S_18-May-09 15:25
professional_Damian S_18-May-09 15:25 
GeneralRe: Random Numbers Pin
GregoryWB18-May-09 15:39
GregoryWB18-May-09 15:39 
AnswerRe: Random Numbers Pin
Luc Pattyn18-May-09 15:38
sitebuilderLuc Pattyn18-May-09 15:38 
GeneralRe: Random Numbers Pin
GregoryWB18-May-09 15:42
GregoryWB18-May-09 15:42 
GeneralRe: Random Numbers Pin
Luc Pattyn18-May-09 15:58
sitebuilderLuc Pattyn18-May-09 15:58 
GeneralRe: Random Numbers Pin
_Damian S_18-May-09 17:13
professional_Damian S_18-May-09 17:13 
AnswerRe: Random Numbers Pin
TheMrProgrammer19-May-09 3:02
TheMrProgrammer19-May-09 3:02 
QuestionDesign Logic for Simple Application Pin
Nielvh18-May-09 12:42
Nielvh18-May-09 12:42 
AnswerRe: Design Logic for Simple Application Pin
_Damian S_18-May-09 14:10
professional_Damian S_18-May-09 14:10 
GeneralRe: Design Logic for Simple Application Pin
Nielvh18-May-09 20:14
Nielvh18-May-09 20:14 
GeneralRe: Design Logic for Simple Application Pin
_Damian S_18-May-09 20:45
professional_Damian S_18-May-09 20:45 
AnswerRe: Design Logic for Simple Application Pin
Mycroft Holmes18-May-09 16:23
professionalMycroft Holmes18-May-09 16:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.