Results 1 to 4 of 4

Thread: Why Bad File Mode?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216

    Unhappy Why Bad File Mode?

    I am just trying to read the first line in a textfile, make some decisions, then re-write the file with the NEW string. But it tells me Bad File Mode on the line in red. Why?
    Thanks
    Code:
        For i = 0 To UBound(arrTheRamFiles)
            lblStatus.Caption = "Reading " & arrTheRamFiles(i)
            Set objTextStream = objFso.OpenTextFile(arrTheRamFiles(i))
            If Not objTextStream.AtEndOfStream Then
                strWhatIsInTheRAMFile = objTextStream.ReadLine
                ' indicates no ?parameters at the end of the string
                If LCase(Mid(strWhatIsInTheRAMFile, Len(strWhatIsInTheRAMFile), 1)) = "m" Then
                    strWhatIsInTheRAMFile = strWhatIsInTheRAMFile & strTheExtraStuff
                Else
                    If InStr(1, LCase(strWhatIsInTheRAMFile), "author") = 0 Then
                        ' add author=
                        strWhatIsInTheRAMFile = strWhatIsInTheRAMFile & "&author=""Coral Ridge Ministries"""
                    End If
                End If
                objTextStream.WriteLine strWhatIsInTheRAMFile 
            End If
            Set objTextStream = Nothing
        Next

  2. #2
    PowerPoster
    Join Date
    Aug 2001
    Location
    new jersey
    Posts
    2,904
    FSO modes include read, write, and append. They do NOT include "read and write at the same time" which is what you are attempting.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216
    Originally posted by phinds
    FSO modes include read, write, and append. They do NOT include "read and write at the same time" which is what you are attempting.
    Thanks I got it! Why oh why don't they do that then?

  4. #4
    PowerPoster
    Join Date
    Aug 2001
    Location
    new jersey
    Posts
    2,904
    file streaming is moderately complicated because files are sequential access thingies and you can screw things up by attempting to write in the middle of a file. There's no way to open it up it you need to write more than what's there and there's no way to condense it if you write less than what's there.

    You have to recreate the file, making your changes as you write the new one.

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