I'm not sure if the coding is correct but I get a file not found error with my dim statement:
Dim mystreamreader As New StreamReader("C:\test.txt", True) if I change it to ("C:\Some_Directory_Name\test.txt", true) i get an error stating that the file is being used by another process.
From every example I have read or examined this seems to be the standard in the Form_load event. I'm confused as to where is should go, along with all the other required code. What exactly goes where as in the Dim statement, what if anything goes in the open and save dialog events? Can I put everything into a btnclick event for say reading? this is what I have so far.
Code:Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim mystreamreader As New StreamReader("C:\test.txt", True) Dim mystreamwriter As New StreamWriter("C:\test.txt", True) While mystreamreader.Peek <> -1 Me.lbxInput.Items.Add(mystreamreader.ReadLine) End While mystreamreader.Close() mystreamreader.Dispose() For Each line As String In Me.lbxInput.Items mystreamwriter.WriteLine(line) Next mystreamwriter.Close() mystreamwriter.Dispose()Code:Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click OpenFileDialog1.InitialDirectory = "C:\test.txt" OpenFileDialog1.Title = "Select a File" OpenFileDialog1.FileName = "" OpenFileDialog1.Filter = "Text Files (*.txt)|*.txt" OpenFileDialog1.FilterIndex = 1 End Sub Private Sub SaveAsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveAsToolStripMenuItem.Click SaveFileDialog1.InitialDirectory = "C:\test.txt" SaveFileDialog1.Title = "Specify destination filename" SaveFileDialog1.Filter = "Text files (*.txt)|*.txt" SaveFileDialog1.FilterIndex = 1 SaveFileDialog1.OverwritePrompt = True End Sub




Reply With Quote