[RESOLVED] Stream i/o issue
Hi,
Just starting up on VB 2008 Express (.NET).
Trying to write to and read from a file.
It runs without errors, but the messagebox only shows the 'OK' button, not the contents of the file as I want. I thought that maybe I have to rewind the file before reading, but AFAICS there is no 'StreamRead.Rewind' or Reset or something.
What am I missing, please?
Code:
Imports System.IO
Public Class ArrayTest
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strId As String
Dim intPeriod As Int16
Dim intValue As Int16
Dim DataFileName As New String("C:\Documents and Settings\Janneman\Bureaublad\bTFiletest.txt")
Dim objDataFile As New FileStream(DataFileName, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite)
Dim objDataWriter As New StreamWriter(objDataFile)
strId = "Bias"
intPeriod = 25
intValue = 35
objDataWriter.Write(strId & CStr(intPeriod) & CStr(intValue))
If File.Exists(DataFileName) Then
Dim objDataReader As New StreamReader(objDataFile)
MessageBox.Show(objDataReader.ReadToEnd)
Else : MessageBox.Show("File doesn't exist")
End If
objDataWriter.Close()
objDataFile.Close()
End Sub
End Class
Jan Didden