Ok, I know about how to check for the end of a file, but what I need to know, is if you create a new file, thats empty, how do you check if it really is empty, and if its the same as EOF, then what am I doing wrong with this code here:
If Dir(My.Application.Info.DirectoryPath & "\TurbineData.xml") <> "" Then
If (TextBox1.Text.Equals("") Or TextBox2.Text.Equals("") Or TextBox3.Text.Equals("") Or TextBox4.Text.Equals("")) Then
Dim title2 = "Invalid Values"
MsgBox(" Form contains no values to save.", , title2)
Else
Dim ExistingData As New MyDatum
Dim Serializer As New System.Xml.Serialization.XmlSerializer(GetType(MyDatum))
If (File.Exists(My.Application.Info.DirectoryPath & "\TurbineData.xml" & Not EOF(1))) Then
Dim OpenStream As System.IO.FileStream = System.IO.File.Open(My.Application.Info.DirectoryPath & "\TurbineData.xml", IO.FileMode.Open)
ExistingData = Serializer.Deserialize(OpenStream)
OpenStream.Close()
Else
Dim err05 = "File does not Exist"
MsgBox("Creating new XML file.", , err05)
End If
Dim NewData As New MyData
TextBox1.Focus()
NewData.DateStamp = CDate(Date.Today()) 'DateValue(Now)
NewData.TimeStamp = CDate(TimeString())
NewData.Gap = gaptext.Text
ExistingData.Add(NewData)
Dim SaveStream As System.IO.FileStream = System.IO.File.Open(My.Application.Info.DirectoryPath & "\TurbineData.xml", IO.FileMode.Create)
Serializer.Serialize(SaveStream, ExistingData)
SaveStream.Close()
Dim title3 = "Save Alert"
MsgBox("Data Saved to " & My.Application.Info.DirectoryPath & " \TurbineData.xml", , title3)
End If
Else
Dim err05 = "File does not Exist"
MsgBox("Creating new XML file.", , err05)
Dim SaveStream As System.IO.FileStream = System.IO.File.Open(My.Application.Info.DirectoryPath & "\TurbineData.xml", IO.FileMode.Create)
SaveStream.Close()
End If
Thats my code there, and the idea of this is that if the file is empty, then create a new entry in the xml, if the file already has data in it, then add to the file, dont overwrite the data.