5

I have the below code..I am getting an invalid call or procedure at this statement txsOutput.Writeline txsInput1.ReadAll ..The combination file is ust a text file which has some entries in this format

name test.css.

Can someone please tell me what's wrong with the script.

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
user505210
  • 1,362
  • 11
  • 28
  • 50

2 Answers2

10

The error 5 when calling TextStream.WriteLine is typically caused by trying to write data the TextStream can't encode:

Trying to write "U+1F00 ἀ e1 bc 80 GREEK SMALL LETTER ALPHA WITH PSILI" to a stream opened with/for 'ASCII' encoding:

>> 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

To prove this:

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

As the data source (.ReadAll()) seems to come from the WWW, it's probable that it contains non ASCII/ANSI text. Be warned though, just opening the output file for Unicode (=UTF-16) won't help if the input is UTF-8 slurped by .ReadAll() on a ASCII Textstream.

Ekkehard.Horner
  • 38,498
  • 2
  • 45
  • 96
  • I guess u are right..I have one specific css file which is throwing error but other like js and other css are working correctly..not sure what's going on with that file. – user505210 Jun 14 '13 at 15:02
  • I used the first proposition with only 2 parameters, and it did work sometimes (I get my data from a mssql server database). It seems like it works everytime with the solution you gave. Does it mean that forcing overwrite uses the correct encoding ? (Thanks by the way) – matthieusb Jan 10 '17 at 13:55
  • No, the **second** True (unicode) is the true solution. – Ekkehard.Horner Jan 13 '17 at 10:48
0

Without actually seeing that particular input file there isn't much more we can tell you. However, you may be able to isolate the source of the error by replacing:

txsOutput.Writeline txsInput1.ReadAll

with something like this:

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

Inspecting the input file with a hex editor may also be an option.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328