VB: Writing To File...

Discussion in 'OT Technology' started by Fase, Aug 22, 2006.

  1. Fase

    Fase Your Face, In A Pickle Jar.

    Joined:
    Apr 6, 2004
    Messages:
    29,540
    Likes Received:
    0
    Location:
    Windsor, Ont, Canada.
    I can write to a file and everything ok, except it always leaves a return line no matter what I do. I don't want to have to manualy remove the return line so it has to be done thorugh VB.
    Thanks.
     
  2. SLED

    SLED build an idiot proof device and someone else will

    Joined:
    Sep 20, 2001
    Messages:
    28,118
    Likes Received:
    0
    Location:
    AZ, like a bauce!
    are you using .WriteLine() ? I think that will always <CR><LF> when you are writing text. Try posting your code.
     
  3. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    open [filename] for output as #1
    print #1, [string variable]
    close #1
     
  4. Fase

    Fase Your Face, In A Pickle Jar.

    Joined:
    Apr 6, 2004
    Messages:
    29,540
    Likes Received:
    0
    Location:
    Windsor, Ont, Canada.
    That leaves a return line.
     
  5. Fase

    Fase Your Face, In A Pickle Jar.

    Joined:
    Apr 6, 2004
    Messages:
    29,540
    Likes Received:
    0
    Location:
    Windsor, Ont, Canada.
    Note that this creates a new file:

    Code:
    Open (RUNFILES & "KIT" & strKitSerial & ".ini") For Append As #50
            For WriteLine = 0 To (UBound(strWriteLines, 1) - 1)
                Print #50, strWriteLines(WriteLine)
            Next WriteLine
        Close #50
    
     
    Last edited: Aug 23, 2006
  6. Fase

    Fase Your Face, In A Pickle Jar.

    Joined:
    Apr 6, 2004
    Messages:
    29,540
    Likes Received:
    0
    Location:
    Windsor, Ont, Canada.
    What it current does:
    [​IMG]
    What I want it to do:
    [​IMG]
    I don't want that return line as seen in the first picture because some code runs while not EOF and splits each line. That code won't be changed, and I don't want the user manualy removing that line because of many possible reasons.
     
  7. suprer

    suprer New Member

    Joined:
    Aug 28, 2004
    Messages:
    2,781
    Likes Received:
    0
    Location:
    Kirkland, WA
    Use Write instead of WriteLine

    Write - add new line without line break
    WriteLine - with line break
    WriteBlankLines - add blank line(s)
     
  8. Fase

    Fase Your Face, In A Pickle Jar.

    Joined:
    Apr 6, 2004
    Messages:
    29,540
    Likes Received:
    0
    Location:
    Windsor, Ont, Canada.
    Wasn't using write line, but I can use that.
     
  9. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    I don't know why I didn't think to ask this before, but are we helping you do your homework?
     
  10. Fase

    Fase Your Face, In A Pickle Jar.

    Joined:
    Apr 6, 2004
    Messages:
    29,540
    Likes Received:
    0
    Location:
    Windsor, Ont, Canada.
    No. Still summer.

    And writeline method still leaves a return line.
     
  11. Fase

    Fase Your Face, In A Pickle Jar.

    Joined:
    Apr 6, 2004
    Messages:
    29,540
    Likes Received:
    0
    Location:
    Windsor, Ont, Canada.
    Write works :bowdown:

    Thanks everyone
     
  12. mobbarley

    mobbarley Active Member

    Joined:
    Mar 4, 2005
    Messages:
    9,256
    Likes Received:
    2
    Location:
    Sydney
    if you use .write for everything you'll probably want to add & vbCrLf at the ends of the lines where you want them
     

Share This Page