Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Posted

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?

  • Leaders
Posted

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()

Posted

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.

Posted

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?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...