使用FileSystemObject将VBScript代码导出到文本文件

时间:2014-10-10 15:34:14

标签: vb.net vbscript filesystemobject

我希望将以下代码的MsgBox oXMLHttp.responseText部分替换为将结果导出到文本文件的代码。我已检查this post并找到以下代码:

设置objFSO = CreateObject(“Scripting.FileSystemObject”)

' How to write file
outFile="c:\test\autorun.inf"
Set objFile = objFSO.CreateTextFile(outFile,True)
objFile.Write "test string" & vbCrLf
objFile.Close

但是,我不知道如何实际实现这一点。 outFile是要创建的文件的位置和名称吗?我相信它是。但那么objFile.Write "test string" & vbCrLf的目的是什么?我的主要问题是:我打算根据下面的代码告诉创建的FileSystemObject进行处理?

Dim request, oXMLHttp, url
    url = "http://ws.cdyne.com/phoneverify/phoneverify.asmx"

    request = "<?xml version='1.0' encoding='utf-8'?>" & _
    "<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">" & _
    "<soap:Body>" & _
    "<CheckPhoneNumbers xmlns=""http://ws.cdyne.com/PhoneVerify/query"">" & _
    "<PhoneNumbers>" & _
    "<string >1</string>" & _
    "<string >2</string>" & _
    "<string >3</string>" & _
    "<string >4</string>" & _
    "<string >5</string>" & _
    "<string >6</string>" & _
    "<string >7</string>" & _
    "<string >8</string>" & _
    "<string >9</string>" & _
    "<string >10</string>" & _
    "</PhoneNumbers>" & _ 
    "<LicenseKey>Key</LicenseKey>" & _
    "</CheckPhoneNumbers>" & _
    "</soap:Body>" & _
    "</soap:Envelope>"

    Set oXMLHttp = CreateObject("MSXML2.ServerXMLHTTP")
    oXMLHttp.open "POST", url, False
    oXMLHttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
    oXMLHttp.send request
    response = oXMLHttp.responseText

    MsgBox oXMLHttp.responseText

1 个答案:

答案 0 :(得分:1)

  1. 创建FileSystemObject

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    
  2. 使用它来创建表示您要创建的文件的TextStream对象(请参阅CreateTextFile函数的here):

    Set objFile = objFSO.CreateTextFile("c:\yourfile.txt", True)
    
  3. 使用TextStream对象(objFile)将文字写入新文件:

    objFile.Write "some text"
    

    在您的情况下,您似乎想要编写HTTP响应:

    objFile.Write oXMLHttp.responseText
    
  4. 关闭您的文件:

    objFile.Close