Const ForReading = 1, ForWriting = 2, ForAppending = 3
    Dim fs, f
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.OpenTextFile("c:\testfile.txt", ForAppending, 
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TristateFalse)
^^^^^^^^^^^^^^
    f.Write "Hello world!"
    f.Close
---------------
Run-time error '5':
Invalid procedure call or argument
-----------------

解决方案 »

  1.   

    ForAppending = 8
    这些都是系统常数,不需要专门设置
      

  2.   

    呵呵,这是MSDN6.0上的代码,我也没懂它为什么要把ForAppending = 3(我没找相关的Bug报告)因为
    Constant Value Description 
    ForReading 1 Open a file for reading only. You can't write to this file. 
    ForWriting 2 Open a file for writing. 
    ForAppending 8 Open a file and write to the end of the file. 在第2个参数位置设置1、2、8都是正确的但设置3的确是有毛病的!!!
    呵呵,这版的MSDN有毛病,在MSDN July 2001里已经把这段代码该了:
    Sub OpenTextFileTest
       Const ForReading = 1, ForWriting = 2, ForAppending = 8
       Dim fso, f
       Set fso = CreateObject("Scripting.FileSystemObject")
       Set f = fso.OpenTextFile("c:\testfile.txt", ForWriting, True)
       f.Write "Hello world!"
       f.Close
    End Sub呵呵,看来MSDN也害了一些人,建议用MSDN 2001 Oct的