Home All Groups Group Topic Archive Search About
Author
30 Sep 2006 4:43 AM
khan
Hi guys

I see blue line underneat the word FileStream in the following code in
line 2.
Can any one help me to find out what am I missing
Imports System.IO
Imports System.Windows.Forms
Public Class Form1
    Inherits System.Windows.Forms.Form

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)Handles Button1.Click
  1      Dim DestinationLoc = "c:\Stream.txt"
  2      Dim FS As FileStream = New File.Open(DestinationLoc,
FileMode.OpenOrCreate, _
  3      FileAccess.ReadWrite)
  4      Dim s As New StreamWriter(FS)
  5      s.BaseStream.Seek(0, SeekOrigin.End)
  6      s.WriteLine("This is an example of using file handling
concepts in VB .NET.")
  7       s.WriteLine("This concept is interesting.")
  8      s.Close()

    End Sub
End Class

Author
30 Sep 2006 4:45 AM
khan
I am using vb.net 2003
Author
30 Sep 2006 6:51 AM
HKSHK
Dear khan,

from the VB.NET help:
Imports System
Imports System.IO

Class Test
     Public Shared Sub Main()
         ' Create an instance of StreamWriter to write text to a file.
         Dim sw As StreamWriter = New StreamWriter("TestFile.txt")
         ' Add some text to the file.
         sw.Write("This is the ")
         sw.WriteLine("header for the file.")
         sw.WriteLine("-------------------")
         ' Arbitrary objects can also be written to the file.
         sw.Write("The date is: ")
         sw.WriteLine(DateTime.Now)
         sw.Close()
     End Sub
End Class

Best Regards,

HKSHK

khan wrote:
Show quoteHide quote
> Hi guys
>
>  I see blue line underneat the word FileStream in the following code in
> line 2.
> Can any one help me to find out what am I missing
> Imports System.IO
> Imports System.Windows.Forms
> Public Class Form1
>     Inherits System.Windows.Forms.Form
>
>     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs)Handles Button1.Click
>   1      Dim DestinationLoc = "c:\Stream.txt"
>   2      Dim FS As FileStream = New File.Open(DestinationLoc,
> FileMode.OpenOrCreate, _
>   3      FileAccess.ReadWrite)
>   4      Dim s As New StreamWriter(FS)
>   5      s.BaseStream.Seek(0, SeekOrigin.End)
>   6      s.WriteLine("This is an example of using file handling
> concepts in VB .NET.")
>   7       s.WriteLine("This concept is interesting.")
>   8      s.Close()
>
>     End Sub
> End Class
>
Author
30 Sep 2006 8:21 AM
Tom Shelton
khan wrote:
Show quoteHide quote
> Hi guys
>
>  I see blue line underneat the word FileStream in the following code in
> line 2.
> Can any one help me to find out what am I missing
> Imports System.IO
> Imports System.Windows.Forms
> Public Class Form1
>     Inherits System.Windows.Forms.Form
>
>     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs)Handles Button1.Click
>   1      Dim DestinationLoc = "c:\Stream.txt"
>   2      Dim FS As FileStream = New File.Open(DestinationLoc,
> FileMode.OpenOrCreate, _
>   3      FileAccess.ReadWrite)

Take out the new.  File.Open returns a FileStream object - you don't
have to create it:

Dim fs As FileStream = File.Open (DestinationLoc, _
    FileMode.OpenOrCreate, FileAccess.ReadWrite)

HTH
--
Tom Shelton
Author
30 Sep 2006 8:26 AM
Tom Shelton
khan wrote:
Show quoteHide quote
> Hi guys
>
>  I see blue line underneat the word FileStream in the following code in
> line 2.
> Can any one help me to find out what am I missing
> Imports System.IO
> Imports System.Windows.Forms
> Public Class Form1
>     Inherits System.Windows.Forms.Form
>
>     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs)Handles Button1.Click
>   1      Dim DestinationLoc = "c:\Stream.txt"
>   2      Dim FS As FileStream = New File.Open(DestinationLoc,
> FileMode.OpenOrCreate, _
>   3      FileAccess.ReadWrite)
>   4      Dim s As New StreamWriter(FS)
>   5      s.BaseStream.Seek(0, SeekOrigin.End)
>   6      s.WriteLine("This is an example of using file handling
> concepts in VB .NET.")
>   7       s.WriteLine("This concept is interesting.")
>   8      s.Close()
>
>     End Sub
> End Class

Hmm, looking further - you could simplify this code:

Dim s As New StreamWriter ("c:\Stream.txt")
s.WriteLine ("This....")
s.WriteLine ("This con...")
s.Close ()

Of course, you might want to do some error trapping in there in real
life :)

--
Tom Shelton