VBS中CreateTextFiles调用失败返回值可能是什么,程序中应该怎样判断
请VBS高手指教,谢谢!

解决方案 »

  1.   

    摘自MSDNCreateTextFile Method  Language Reference 
    Version 2 
     See Also                   Applies To 
    --------------------------------------------------------------------------------Description
    Creates a specified file name and returns a TextStream object that can be used to read from or write to the file.
    Syntax
    object.CreateTextFile(filename[, overwrite[, unicode]])
    The CreateTextFile method has these parts:Part Description 
    object Required. Always the name of a FileSystemObject or Folder object. 
    filename Required. String expression that identifies the file to create. 
    overwrite Optional. Boolean value that indicates whether you can overwrite an existing file. The value is true if the file can be overwritten, false if it can't be overwritten. If omitted, existing files are not overwritten. 
    unicode Optional. Boolean value that indicates whether the file is created as a Unicode or ASCII file. The value is true if the file is created as a Unicode file, false if it's created as an ASCII file. If omitted, an ASCII file is assumed. 
    Res
    The following code illustrates how to use the CreateTextFile method to create and open a text file: 
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    var a = fso.CreateTextFile("c:\\testfile.txt", true);
    a.WriteLine("This is a test.");
    a.Close();
      

  2.   

    如果CreateTextFile指定一个不存在的文件路径,会弹出出错对话框,怎样自己检测可以创建文件避免弹出错误框呢?
      

  3.   

    不知道VBS里有没有dir语句.用它可以知道有没有这个文件.
      

  4.   

    strpath="c:\ddd\test.txt"set fso = createobject("Scripting.FileSystemObject")
    if fso.folderexists(left(strpath,instrrev(strpath,"\"))) then
      set a = fso.CreateTextFile(strpath, true)
      a.WriteLine("xxx")
      a.Close()
    else
      msgbox "路径不存在!",vbexclamation
    end if
      

  5.   

    如果我不想判断,而是直接调用CreateTextFiles,VBS中有异常处理吗?(我不希望看到错误框,而是希望程序可以捕获异常然后进行处理),可以实现吗???
      

  6.   

    运行结果你已经知道了,路径不存在就是报错退出,组件就是这样设计的你有什么办法,要么就在它的下一行检测下错误代码。strpath="c:\ddd\test.txt"on error resume next
    set fso = createobject("Scripting.FileSystemObject")
    set a = fso.CreateTextFile(strpath, true)if err.number>0 then 
      msgbox "错误号: " & err.number & vbcrlf & "错误描述: " & err.description
    end ifa.WriteLine("xxx")
    a.Close()
      

  7.   

    <H3> Thank you for submitting your information </H3>
          <%
          '-----------------------------------------------------
          ' FileSystemObject constants include file for VBScript
          '-----------------------------------------------------      '---- iomode Values ----
          Const ForAppending = 8
          Const ForReading = 1
          Const ForWriting = 2      '---- format Values ----
          Const TristateFalse = 0
          Const TristateMixed = -2
          Const TristateTrue = -1
          Const TristateUseDefault = -2      ' If the file already exists, then an error will be generated.
          ' This line permits the program to continue executing on error.
          ' Resume next.
          ' Create the scripting object.
          set objfso = createobject("scripting.FileSystemObject")      ' Create the text file. If the file already exists, then an error
          ' will be generated.
          set myobject = objfso.createtextfile("c:\public\myfile.txt", false)      ' Open the file for scripting.
          set myobject = objfso.opentextfile("c:\public\myfile.txt", forappending )      'Calculate the total price.
          quantity = request.form("quantity")
          price = request.form("price")
          totalprice = quantity * price      ' Assign the submitted form results to a variable.
          productdata = request.form("name") & "," & request.form("product") & "," &
          request.form("quantity") & "," & request.form("price") & "," & totalprice      ' Write the form results to the file.
          myobject.writeline(productdata)      ' Close the object.
          myobject.close
          %>
      

  8.   

    Set fs = CreateObject("Scripting.FileSystemObject")
    Set aFile = fs.CreateTextFile("c:\SiteAccessFile.txt", True)
    aFile.WriteLine("You just wrote to a text file!")
    aFile.Close
      

  9.   

    ??
    这个是asp代码,功能是将表单传递过来的数据保存到本地的文本文件中。和主题貌似无关。
      

  10.   

    创建一个指定的文件名并且返回一个用于该文件读写的 TextStream 对象。
    应该判断的是错误号不是其返回值
      

  11.   

    主题帖是说VBS
    ASP代码不是VBS写的?
      

  12.   

    主题是这个方法执行失败返回值,那个asp代码只是写入文件范例,没涉及写入失败错误捕获什么的类似于1楼的例子:
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    var a = fso.CreateTextFile("c:\\testfile.txt", true);
    a.WriteLine("This is a test.");
    a.Close();
      

  13.   

    那也是VBS,不是VB
    #10楼 已经回答了