Results 1 to 6 of 6

Thread: [02/03] I think my streamwriter is broken :(

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2005
    Posts
    257

    [02/03] I think my streamwriter is broken :(

    Here's the code:
    VB Code:
    1. Dim oMotor As New Motors
    2.             'delete the file so it's remade blank for a new save
    3.             IO.File.Delete(Application.StartupPath & "\motors2.txt")
    4.             Dim AppendWriter As New StreamWriter(Application.StartupPath & "\motors2.txt", True)
    5.             For Each oMotor In MyBase.List
    6.                 Dim strToWrite As String
    7.                 strToWrite = oMotor.MotorID & "|" & oMotor.RPM & "|" & oMotor.voltage & "|" & oMotor.status & "|" & oMotor.Description
    8.                 AppendWriter.WriteLine(strToWrite)
    9.             Next

    And here's a screenshot of it claiming to write the correct string:


    and the file when it's all done saving should contain this:
    14491|5000|120|ON|This is the best motor ever!
    12427|4000|240|OFF|This motor is cool too
    1238A|9000|120|OFF|This motor sucks
    11234|2000|50|OFF|This is another motor
    13421|9000|75|MNT|This motor is busted
    1239B|9000|120|NA|This is the other 1239
    54677|1234|80|MNT|This motor is cooooool
    23467|9500|150|ON|My favorite motor
    214SE|3589|120|ON|The SE model
    75634|4000|234|OFF|It broke cuz it's 234 volts

    but instead, the file is completely blank when it's all done! I even looked at the file while stepping through it when it was supposed to have written 1, 2, and 3 lines and it was blank then too. Why is my streamwriter not writing anything?
    I tried to end process on Visual Studio 2005
    but PETA stopped me saying it's smart enough
    to be a living creature

  2. #2
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: [02/03] I think my streamwriter is broken :(

    Do you close the file when you are done?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2005
    Posts
    257

    Re: [02/03] I think my streamwriter is broken :(

    oops I didn't know it doesn't actually write until you close it (cuz that's a really dumb way to set it up, Microsoft!)
    I tried to end process on Visual Studio 2005
    but PETA stopped me saying it's smart enough
    to be a living creature

  4. #4
    Hyperactive Member
    Join Date
    Mar 2005
    Location
    Bath, England
    Posts
    411

    Re: [02/03] I think my streamwriter is broken :(

    It writes every time the buffer is flushed, to save performing the time-consuming write operation every time you want to write a line to the file. The buffer is flushed regularly, if you call "StreamWriter.flush()", or when you close the file.

    So actually Microsoft handles it pretty well...
    "Make it idiot-proof and someone will make a better idiot"

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2005
    Posts
    257

    Re: [02/03] I think my streamwriter is broken :(

    well isn't it automatically flushed when I close the program? It didn't write anything then
    I tried to end process on Visual Studio 2005
    but PETA stopped me saying it's smart enough
    to be a living creature

  6. #6
    Fanatic Member cpatzer's Avatar
    Join Date
    Sep 2004
    Posts
    537

    Re: [02/03] I think my streamwriter is broken :(

    AppendWriter.Close()
    In life you can be sure of only two things... death and taxes. I'll take death.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width