Jay1b Posted September 4, 2003 Posted September 4, 2003 I copied the majority of the following text from the msdn library, but I have those annoying lilttle blue lines under the imports section and the file in the file.append bit. Imports System Imports System.IO Public Sub ReadBuffer2() Dim path As String = "c:\MyTest.txt" Dim sw As StreamWriter sw = File.AppendText(path) sw.WriteLine("This") sw.WriteLine("is Extra") sw.WriteLine("Text") sw.Flush() sw.Close() End Sub I can get arid of the imports section by putting system.io before streamwriter - but i still get the line under the FILE in file.append Thanks. Quote
Jay1b Posted September 4, 2003 Author Posted September 4, 2003 I would just like to say that i have done this another way, but i just want to know why this isnt working. As i cant see why it shouldnt. The way i have done it is: Public Sub ReadBuffer2() Dim sw As New System.IO.StreamWriter("C:\test.txt", True) sw.WriteLine("This") sw.WriteLine("is Extra") sw.WriteLine("Text") sw.Flush() sw.Close() End Sub But could someone please tell me why the first script didnt work please? Quote
Leaders dynamic_sysop Posted September 4, 2003 Leaders Posted September 4, 2003 the easiest way would be like this.... Dim path As String = "c:\MyTest.txt" Dim sWriter As New StreamWriter(New FileStream(path, FileMode.OpenOrCreate)) With sWriter .WriteLine("test") .WriteLine("123") .WriteLine("456") End With sWriter.Close() although when i tried your first method.... Dim path As String = "c:\MyTest.txt" Dim sw As StreamWriter sw = File.AppendText(path) sw.WriteLine("This") sw.WriteLine("is Extra") sw.WriteLine("Text") sw.Flush() sw.Close() that also worked and that could also be shortned slightly to still work , like this... Dim path As String = "c:\MyTest.txt" Dim sw As StreamWriter = File.AppendText(path) With sw .WriteLine("This") .WriteLine("is Extra") .WriteLine("Text") .Flush() End With sw.Close() Quote
Jay1b Posted September 4, 2003 Author Posted September 4, 2003 hmmm...... When i tried it, it found a problem with the FILE bit, namely File itself. Maybe the bit infront of the FILE hadnt been imported correctly. I know streamwriter is system.io, what would FILE's be? Thank you. Quote
*Experts* mutant Posted September 4, 2003 *Experts* Posted September 4, 2003 File class is in the System.IO namespace too. What are the exact errors you are getting? Quote
Jay1b Posted September 5, 2003 Author Posted September 5, 2003 I was just getting the blue line underneath it, i have found another way of doing it, i just wanted to know why it didnt work. It was because the system.io was being called infront of the FILE. When you use: IMPORTS System IMPORTS System.IO Can these go anywhere, or just in certain places? Quote
Administrators PlausiblyDamp Posted September 5, 2003 Administrators Posted September 5, 2003 The imports need to go above the class declaration - I just put them at the top of the file below Option Explicit On and Option Strict On Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.