www.webdeveloper.com
Results 1 to 4 of 4

Thread: VBS OpenAsTextStream Error

  1. #1
    Join Date
    Aug 2004
    Posts
    20

    VBS OpenAsTextStream Error

    Here is the code. The comment line indicates where the error occurs, and its type. I hope that someone can tell me what is wrong.

    <HTML>
    <Head>
    <Title>Saved Content</Title>
    <Script Language=JavaScript></Script>
    <Script language='VBScript'>

    Sub saveThis_OnClick
    isData = xferContent.innerHTML
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set contentFile = fso.CreateTextFile("c:\My Documents\Test.txt",True)
    contentFile.WriteLine(isData)
    contentFile.Close
    MsgBox "Successfully saved Test.txt in My Documents"
    End Sub

    Sub appendThis_onClick
    isData = appendContent.innerHTML
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set contentFile = fso.GetFile("c:\My Documents\Test.txt")

    // ---- Why does this line cause an "invalid procedure call or argument" error ----
    Set textStream = contentFile.OpenAsTextStream(ForAppending)

    End Sub

    </Script>
    </Head>
    <Body>
    <center>
    <Div id=xferContent>
    This is some text
    </Div>
    <Div id=appendContent>
    And this text will be appended to the existing file
    </Div>
    <br>
    <input type=button id=saveBtn Name='saveThis' value='Save as a text file'>
    <br><br>
    <input type=button id=appendBtn value='Append this to text file' Name='appendThis'>
    </center>
    </Body>
    </HTML>

  2. #2
    Join Date
    Jan 2004
    Location
    Melbourne, Australia
    Posts
    5,298
    Try using the literal value of the ForWriting constant instead.
    Code:
    Set textStream = contentFile.OpenAsTextStream(8)
    Regards.

  3. #3
    Join Date
    Jan 2004
    Location
    Melbourne, Australia
    Posts
    5,298
    So you tried writing 8 instead of ForAppending?

    The constants might be inside an include file somewhere and may not be available to you without explicit inclusion.

    Regards.

  4. #4
    Join Date
    Aug 2004
    Posts
    20
    Never mind. I found the solution on Microsoft web site.
    Thanks anyway.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles