K
Ken Hall
I have the following code to read the following file (very simple).
I'm trying to extract only the date, but with this code I'm extracting
the entire record. What am I doing wrong? What am I missing?
Ken
c:\temp\namedate.txt = Ken Hall08/27/56 (One record)
Module Module1
Public Structure Record1
<VBFixedString(8)> Public name As String
<VBFixedString(8)> Public date1 As String
End Structure
Sub Main()
Try
Dim line As String
Dim Record2 As New Record1
' Create an instance of StreamReader to read from a file.
Dim sr As System.IO.StreamReader = New
System.IO.StreamReader("c:\temp\namedate.txt")
' Read and display the lines from the file until the end
' of the file is reached.
Do
line = sr.ReadLine()
Record2.date1 = line
Console.WriteLine(Record2.date1)
Loop Until line Is Nothing
sr.Close()
Catch E As Exception
' Let the user know what went wrong.
Console.WriteLine("The file could not be read:")
Console.WriteLine(E.Message)
End Try
End Sub
End Module
I'm trying to extract only the date, but with this code I'm extracting
the entire record. What am I doing wrong? What am I missing?
Ken
c:\temp\namedate.txt = Ken Hall08/27/56 (One record)
Module Module1
Public Structure Record1
<VBFixedString(8)> Public name As String
<VBFixedString(8)> Public date1 As String
End Structure
Sub Main()
Try
Dim line As String
Dim Record2 As New Record1
' Create an instance of StreamReader to read from a file.
Dim sr As System.IO.StreamReader = New
System.IO.StreamReader("c:\temp\namedate.txt")
' Read and display the lines from the file until the end
' of the file is reached.
Do
line = sr.ReadLine()
Record2.date1 = line
Console.WriteLine(Record2.date1)
Loop Until line Is Nothing
sr.Close()
Catch E As Exception
' Let the user know what went wrong.
Console.WriteLine("The file could not be read:")
Console.WriteLine(E.Message)
End Try
End Sub
End Module