在vbscript中获取无效的过程调用或参数

时间:2013-06-13 18:21:21

标签: vbscript

我有以下代码..我在此语句中收到无效的调用或过程txsOutput.Writeline txsInput1.ReadAll ..组合文件是一个文本文件,其中包含一些此格式的条目

name test.css。

有人可以告诉我这个剧本有什么问题。

Dim strInputPath1
Dim txsInput1,txsOutput
Dim FSO

Dim Filename


Set FSO = CreateObject("Scripting.FileSystemObject")
strOutputPath = "C:\txt3.txt"
Set txsOutput = FSO.CreateTextFile(strOutputPath)

Set re = New RegExp
re.Pattern = "\s+"
re.Global  = True

Set f = FSO.OpenTextFile("C:\combination.txt")
Do Until f.AtEndOfStream
  tokens = Split(Trim(re.Replace(f.ReadLine, " ")))
  extension = Split(tokens(0),".")
  strInputPath1 =  "C:\inetpub\wwwroot\data\p\" & tokens(1) & "\" & extension(1) & "\" & tokens(0) 

Loop
f.Close

WScript.Echo strInputPath1

Set txsInput1 = FSO.OpenTextFile(strInputPath1, 1)
txsOutput.Writeline txsInput1.ReadAll

txsInput1.Close
txsOutput.Close

2 个答案:

答案 0 :(得分:8)

调用TextStream.WriteLine时的错误5通常是由于尝试写入TextStream无法编码的数据引起的:

尝试将“U + 1F00ἀe1 bc 80 GREEK SMALL LETTER ALPHA with PSILI”写入用'ASCII'编码打开的流:

>> Set f = goFS.CreateTextFile(".\tmp.txt")
>> f.WriteLine "AÄ"
>>  --- no news here means: written ---
>> f.WriteLine ChrW(&H1F00)
>>
Error Number:       5
Error Description:  Invalid procedure call or argument

证明这一点:

>> f.close
>> Set f = goFS.CreateTextFile(".\tmp.txt", True, True) ' overwrite, unicode
>> f.WriteLine ChrW(&H1F00)
>>
>> --- no news are good news --

由于数据源(.ReadAll())似乎来自WWW,因此很可能它包含非ASCII / ANSI文本。但是请注意,如果输入是由ASCII文本流上的.ReadAll()输入的UTF-8,那么打开Unicode(= UTF-16)的输出文件将无济于事。

答案 1 :(得分:0)

如果没有真正看到特定的输入文件,我们可以告诉您更多信息。但是,您可以通过替换:

来隔离错误的来源
txsOutput.Writeline txsInput1.ReadAll

有这样的事情:

On Error Resume Next
Do Until txsInput1.AtEndOfStream
  line = txsInput1.ReadLine
  If Err Then
    WScript.Echo "Operation:   Read" & vbNewLine _
      "Error:       " & Err.Number & vbNewLine _
      "Description: " & Err.Description & vbNewLine _
      "Line:        " & txsInput1.Line
    WScript.Echo "Text:        " & line
  End If
  Err.Clear

  txsOutput.WriteLine line
  If Err Then
    WScript.Echo "Operation:   Write" & vbNewLine _
      "Error:       " & Err.Number & vbNewLine _
      "Description: " & Err.Description & vbNewLine _
      "Line:        " & txsInput1.Line
    WScript.Echo "Text:        " & line
  End If
  Err.Clear
Loop
On Error Goto 0

使用十六进制编辑器检查输入文件也可能是一种选择。