locked
Simple Text File Output RRS feed

  • Question

  •  

    Why is this so hard? Writing my first app in VB 2005 Express / SP1. Took example right from help. Gotta work right? It doesn't! It won't write a simple file correctly? 3 garbage characters prefix Hello World in output file.

    Output is ∩╗┐Hello World. 

    Note: you can't tell from Notepad.

    Must either enter c:> type c:\text.txt from command prompt or display via hex editor to see added garbage.

     

    Help please.

    Thanks, Tim

     

    Sub Main()

    Dim myfile As System.IO.StreamWriter

    myfile = My.Computer.FileSystem.OpenTextFileWriter("c:\test.txt", False)

    myfile.WriteLine("Hello World")

    myfile.Close()

    End Sub

    Sunday, April 22, 2007 8:23 AM

Answers

  • Try this

     

    Code Snippet

    Sub Main()

    Dim myfile As New System.IO.StreamWriter("c:\test.txt", False)

    myfile.WriteLine("Hello World")

    myfile.Close()

    End Sub

     

     

    Sunday, April 22, 2007 11:21 AM

All replies

  • Try this

     

    Code Snippet

    Sub Main()

    Dim myfile As New System.IO.StreamWriter("c:\test.txt", False)

    myfile.WriteLine("Hello World")

    myfile.Close()

    End Sub

     

     

    Sunday, April 22, 2007 11:21 AM
  • hi,

      the old way of doing that still works...

     

    Dim filenum As Integer = FreeFile()

    Dim strLine As String

    FileOpen(filenum, "c:\test.txt", OpenMode.Output, OpenAccess.Write, OpenShare.Shared)

    Write(filenum, "Hello World")

    FileClose(filenum)

     

    FileOpen(filenum, "c:\test.txt", OpenMode.Input, OpenAccess.Read, OpenShare.Shared)

    Input(filenum, strLine)

    FileClose(filenum)

     

    that might be an option.

     

    BadButBit

    Sunday, April 22, 2007 1:06 PM
  • Thanks bd...

    That worked.

    Still doesn't give me warm fuzzy when simple example code doesn't work.

    Wonder what else I need to look out for.

    Any way, Thanks again,

    Tim

    Sunday, April 22, 2007 7:24 PM
  • You got me why it didn't work as you say it is right from the examples . Perhaps they missed using the new keyword .
    Sunday, April 22, 2007 11:24 PM