View Single Post
  #1 (permalink)  
Old 05-07-04, 03:15 PM
ZodKneelsFirst ZodKneelsFirst is offline
New Member
 
Join Date: May 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
StreamWriter probs

Hello,

Very novicey I'm afraid so feel free to sneer.

This code is creating a new file OK.
what I don't unsderstand is why the file appears to be blank after termination.

Ta.

Imports System.IO.Stream
Imports System
Imports System.IO
Public Class Form1
Inherits System.Windows.Forms.Form
Dim strPath As String = "C:\VSdata\FileReader\outputfile"
Dim filename As Int16 = 1
Dim ext As String = ".txt"
Dim fsIn As New FileStream("C:\VSdata\FileReader\testfile.txt", FileMode.Open)
Dim srIn As New StreamReader(fsIn)

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
While File.Exists(strPath + filename.ToString() + ext)
filename += 1
End While

Try
Dim fsOut As New FileStream(strPath + filename.ToString() + ext, FileMode.OpenOrCreate)
Dim swOut As StreamWriter = New StreamWriter(fsOut)
Dim inString As String
While (inString <> Nothing)
Try
swOut.WriteLine(inString)
inString = srIn.ReadLine()
Catch excp As System.Exception
MsgBox(excp.Message)
End Try
End While

Catch exp As System.Exception
MsgBox(exp.Message)
End Try

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

End Sub
End Class
Reply With Quote