Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 150,086 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,767 people online right now. Registration is fast and FREE... Join Now!




Streamwriter

 
Reply to this topicStart new topic

Streamwriter, Doesn't Write anything

ferrari12508
22 Jun, 2008 - 12:25 PM
Post #1

D.I.C Lover
Group Icon

Joined: 2 Nov, 2007
Posts: 1,112



Thanked: 2 times
Dream Kudos: 150
My Contributions
CODE

Dim writer as IO.streamwriter
If IO.File.Exists("C:\Program Files\Apache Group\Apache2\htdocs\Music\" & TextBox1.Text & " - " & TextBox2.Text) Then
    MessageBox.Show("File already Exists", "Exists", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
    Filename = TextBox1.Text & " - " & TextBox2.Text
    writer = IO.File.CreateText(Filename & ".html")
    writer.Write("<html>" & ControlChars.NewLine & "<a href=" & """ & Filename & """ & ">" & Filename & "</a>")
End If


When I execute the code, it works, but when I look at the file, there is no text inside of it. can anyone explain why?
User is offlineProfile CardPM
+Quote Post

ferrari12508
RE: Streamwriter
22 Jun, 2008 - 12:45 PM
Post #2

D.I.C Lover
Group Icon

Joined: 2 Nov, 2007
Posts: 1,112



Thanked: 2 times
Dream Kudos: 150
My Contributions
False alarm, the code still does not work

This post has been edited by ferrari12508: 22 Jun, 2008 - 12:49 PM
User is offlineProfile CardPM
+Quote Post

AdamSpeight2008
RE: Streamwriter
22 Jun, 2008 - 01:26 PM
Post #3

LINQ D.I.C.
Group Icon

Joined: 29 May, 2008
Posts: 863



Thanked: 54 times
Dream Kudos: 2250
My Contributions
QUOTE(ferrari12508 @ 22 Jun, 2008 - 09:25 PM) *

CODE

Dim writer as IO.streamwriter
If IO.File.Exists("C:\Program Files\Apache Group\Apache2\htdocs\Music\" & TextBox1.Text & " - " & TextBox2.Text) Then
    MessageBox.Show("File already Exists", "Exists", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
    Filename = TextBox1.Text & " - " & TextBox2.Text
    writer = IO.File.CreateText(Filename & ".html")
    writer.Write("<html>" & ControlChars.NewLine & "<a href=" & """ & Filename & """ & ">" & Filename & "</a>")
End If


When I execute the code, it works, but when I look at the file, there is no text inside of it. can anyone explain why?


You need to close the stream.

CODE

writer.close

User is offlineProfile CardPM
+Quote Post

ferrari12508
RE: Streamwriter
22 Jun, 2008 - 03:33 PM
Post #4

D.I.C Lover
Group Icon

Joined: 2 Nov, 2007
Posts: 1,112



Thanked: 2 times
Dream Kudos: 150
My Contributions
Thank you. I ha that after my if statement, but I was just wondering why it wasnt writing anything. I did get it working though, thanks
User is offlineProfile CardPM
+Quote Post

AdamSpeight2008
RE: Streamwriter
22 Jun, 2008 - 04:14 PM
Post #5

LINQ D.I.C.
Group Icon

Joined: 29 May, 2008
Posts: 863



Thanked: 54 times
Dream Kudos: 2250
My Contributions
It won't write to the file by default.
Unless you close the stream, where it write every in on go.

CODE

writer.flush' Transfers what has been written so far to file


Transfer straight to file after a write. Use
CODE

writer = IO.File.CreateText(Filename & ".html")
writer.AutoFlush=true

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 11:52PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month