Microsoft vbscript runtime error invalid procedure call or argument

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

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:inetpubwwwrootdatap" & 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

asked Jun 13, 2013 at 18:21

user505210's user avatar

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.

answered Jun 13, 2013 at 18:57

Ekkehard.Horner's user avatar

Ekkehard.HornerEkkehard.Horner

38.3k2 gold badges44 silver badges94 bronze badges

3

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.

answered Jun 14, 2013 at 17:02

Ansgar Wiechers's user avatar

Ansgar WiechersAnsgar Wiechers

189k23 gold badges241 silver badges313 bronze badges

  • Remove From My Forums
  • Question

  • I am using a vbscript to read the contents of a text file and write the contents to a CSV file. It works most of the time.

    However for some files, it will throw error «invalid procedure call or argument». By capturing the error codes and the line exactly where it occurs, I found that its normally the long line of entry in the text file that throws the error (or may
    be a special hidden character). For example, I have copied some contents of a text file and the line which is underlined throws the error. Not sure how to tackle it.

    The script:

    On Error Resume Next

    ‘get date in yyyymmdd format
    sDay = Day(Now())
      If Len(sDay) = 1 Then sDay = «0» & Day(Now())
      sMonth = Month(Now())
      If Len(sMonth) = 1 Then sMonth = «0» & Month(Now())
      sYear = Year(Now())
      sDate = sYear & sMonth & sDay

     
     
    Const ForReading = 1
    Const ForWriting = 2
    Const ForAppending = 8

    Set objFSO = CreateObject(«Scripting.FileSystemObject»)
    Set objInpoutFile = objFSO.OpenTextFile(«.SNMP.TXT»,1)
    Set objOutputFile = objFSO.OpenTextFile(«.snmp_» & sDate & «.csv»,2,True)

        objOutputFile.write(«Time»)
        objOutputFile.Write(«,»)
        objOutputFile.write(«EntSpecific»)
        objOutputFile.Write(«,»)
        objOutputFile.write(«generic»)
        objOutputFile.Write(«,»)
        objOutputFile.write(«Specific»)
        objOutputFile.Write(«,»)
        objOutputFile.write(«OID»)
        objOutputFile.Write(«,»)
        objOutputFile.write(«Source»)
        objOutputFile.Write(«,»)

    do while not objInpoutFile.AtEndOfStream
        lineread =  objInpoutFile.ReadLine()

        
        If ((Left(lineread,2)) = «>>») Then
            ‘if line starts with >>, start a new line and put the time stamp from the content
            datestr = Left(lineread,25)
            timestamp = Right(datestr,8)
            objOutputFile.write(vbCrLf)
            objOutputFile.Write(timestamp)
            objOutputFile.Write(«,»)

            
        elseif ((Left(lineread,1)) = «») Then
            ‘if bliank line, skip the line

                    
        else
        ‘write the line to file with comma at the end
        objOutputFile.Write (lineread)
        objOutputFile.Write («,»)

        end If

    loop

        
    ‘If Err.Number <> 0 Then
    ‘    ‘error handling:
    ‘    WScript.Echo «Line: » & x & «Error no: » & Err.Number & » Srce: » & Err.Source & » Desc: » &  Err.Description
     ‘   Err.Clear
    ‘End If

        
    objInpoutFile.Close
    objOutputFile.Close

    Content of File that throws error (line that is underlined):

    >>>> 23 Apr 2013 00:13:08 — Unhandled (Source not monitored)

    SNMPv2 Trap (enterpriseSpecific = 101)
    Generic: 6
    Specific: 101
    Enterprise Oid: 1.3.6.1.4.1.33386
    Source: x.x.x.x
    Community: xxxxx
    Variable: 1.3.6.1.2.1.1.3.0
    Type: Time Click
    Value: 0
    Variable: 1.3.6.1.6.3.1.1.4.1.0
    Type: OID
    Value: 1.3.6.1.4.1.33386.1.101
    Variable: 1.3.6.1.6.3.1.1.4.3.0
    Type: OID
    Value: 1.3.6.1.4.1.33386
    Variable: 1.3.6.1.4.1.33386.2.11
    Type: String
    Value: High VM Memory Utilization
    Variable: 1.3.6.1.4.1.33386.2.1
    Type: String
    Value: Memory utilization of the VM over 70% (xxxxxxx)
    Variable: 1.3.6.1.4.1.33386.2.2
    Type: String
    Value:
    Variable: 1.3.6.1.4.1.33386.2.4
    Type: String
    Value: Warning
    Variable: 1.3.6.1.4.1.33386.2.7
    Type: String
    Value: Any
    Variable: 1.3.6.1.4.1.33386.2.3
    Type: String
    Value: 1.0
    Variable: 1.3.6.1.4.1.33386.2.5
    Type: String
    Value: NULL
    Variable: 1.3.6.1.4.1.33386.2.6
    Type: String
    Value: NULL
    Variable: 1.3.6.1.4.1.33386.2.12
    Type: String
    Value: The memory utilization of the VM is sustaining over 70%.  This could indicate excessive workload activity.  Consider the active links below for further drill down.
    Variable: 1.3.6.1.4.1.33386.2.8.1.2.0
    Type: String
    Value: SVHOF-FS05
    Variable: 1.3.6.1.4.1.33386.2.8.1.1.0
    Type: String
    Value: 5fabc69c-1509-41e6-92b8-759d20924018
    Variable: 1.3.6.1.4.1.33386.2.8.1.3.0
    Type: String
    Value: VirtualMachine
    Variable: 1.3.6.1.4.1.33386.2.8.1.4.0
    Type: String
    Value: 74.86
    Variable: 1.3.6.1.4.1.33386.2.8.1.10.0
    Type: Integer
    Value: 0


    ashabc

Answers

  • Open the file in notepad and save it back as ANSI.  Same name- same location.

    At a prompt type: WSCRIPT //H:cscript

    Now — from a CMD prompt run the same VBS again.


    ¯_(ツ)_/¯

    • Marked as answer by

      Friday, April 26, 2013 3:38 AM

  • I go some clue in the following article,. Hopefully able to get it resolved.

    http://msdn.microsoft.com/en-us/library/windows/desktop/aa368046%28v=vs.85%29.aspx


    ashabc

    Just tri-state the file in the OpenTextFile. 

    fso.OpenTextFile(filename, 1 False, -1)  ‘ Opens Unicode file.

    If the file is not little endian you will have to convert it.


    ¯_(ツ)_/¯

    • Marked as answer by
      ashabc
      Friday, April 26, 2013 4:45 AM

User650332484 posted

Hi Classic ASP Experts,

Basically, I am new to Classic ASP and VBScript, and got this «VBScript runtime error: Invalid procedure call or argument», while trying to pass an argument of complex type to the COM method (vide screenshot below). While the server object is getting created
and the string passed to the COM method, any attempt to pass an argument of complex type goes in vain.

Please help.

Here’s the Code Snippet:

VBScript (server-side) on ClassicASPHome.asp page:

Here’s my VBScript (ClassicASPHome.asp): 

   <% 

   response.write("My first ASP script!")  
     
     set co = Server.CreateObject("ClassicASPCOM.ComplexObject")
     co.Message = "Messi"
     co.Number = 100

    Dim ccom
     Set ccom = Server.CreateObject("ClassicASPCOM.ClassCOM")

    response.Write(ccom.GetMessage("1234567890"))

   ‘—————Works fine till here

    Dim ret

    ‘ —————The following statement throws error

ret = ccom.PaymentDetails(co)

    response.Write("Fine")

    %>

Code Snippet:

// C# Code (ClassicASPCOM.dll) built with Strong Name and Registered for COM Interop:

// Executed the following in Visual Studio Command Prompt in binRelease folder
 // Regasm ClassicASPCOM.dll

// Regasm ClassicASPCOM.dll /codebase

// Regasm ClassicASPCOM.dll /tlb

// gacutil/i ClassicASPCOM.dll

using System;
 using System.Runtime.InteropServices;

namespace ClassicASPCOM
 {
     [ComVisibleAttribute(true)]
     [Guid("D355BC25-B85F-4476-8D38-582F92F7B6F4")]
     public interface IComplexObject
     {
         [DispId(2221)]
         int Number {get; set;}
         [DispId(2222)]
         string Message { get; set; }
         [DispId(2223)]
         DateTime Dtime { get; set; }
     }

    [ComVisibleAttribute(true)]
     [Guid("4E602191-8D09-458E-A0D0-A0A267696F78"),
     ClassInterface(ClassInterfaceType.None)]
     public class ComplexObject :  IComplexObject
     {
         int Nmbr;
         public int Number
         {
             get
             {
                 return Nmbr;
             }
             set
             {
                 Nmbr = value;
             }
         }

        string Msg;
         public string Message
         {
             get
             {
                 return Msg;
             }
             set
             {
                 Msg = value;
             }
         }

        DateTime Dt;
         public DateTime Dtime
         {
             get
             {
                 return Dt;
             }
             set
             {
                 Dt = value;
             }
         }
     }

    [ComVisibleAttribute(true)]
     [Guid("4042FE79-8ACA-4E5D-9F14-2FF7C6AE8D88")]
     public interface IGetMessage
     {
         [DispId(2224)]
         string GetMessage(string Message);
         [DispId(2225)]
         string PaymentDetails(ComplexObject cObject);
     }
     
     [ComVisibleAttribute(true)]
     [Guid("9A133858-5893-4CA7-9048-345CD0FCF535"),
     ClassInterface(ClassInterfaceType.None)]
     public class ClassCOM : IGetMessage
     {
         public string GetMessage(string Message)
         {
             return "Your Message: " + Message;
         }

        public string PaymentDetails(ComplexObject cObject)
         {
             return " Message: " + cObject.Message + " Number: " + cObject.Number;
         }
     }  
 }

Thanks

Содержание

  1. Invalid procedure call or argument microsoft vbscript runtime error
  2. Answered by:
  3. Question
  4. Answers
  5. All replies

Invalid procedure call or argument microsoft vbscript runtime error

This forum is closed. Thank you for your contributions.

Answered by:

Question

I am using a vbscript to read the contents of a text file and write the contents to a CSV file. It works most of the time.

However for some files, it will throw error «invalid procedure call or argument». By capturing the error codes and the line exactly where it occurs, I found that its normally the long line of entry in the text file that throws the error (or may be a special hidden character). For example, I have copied some contents of a text file and the line which is underlined throws the error. Not sure how to tackle it.

The script:

On Error Resume Next

‘get date in yyyymmdd format
sDay = Day(Now())
If Len(sDay) = 1 Then sDay = «0» & Day(Now())
sMonth = Month(Now())
If Len(sMonth) = 1 Then sMonth = «0» & Month(Now())
sYear = Year(Now())
sDate = sYear & sMonth & sDay

Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

Set objFSO = CreateObject(«Scripting.FileSystemObject»)
Set objInpoutFile = objFSO.OpenTextFile(«.SNMP.TXT»,1)
Set objOutputFile = objFSO.OpenTextFile(«.snmp_» & sDate & «.csv»,2,True)

objOutputFile.write(«Time»)
objOutputFile.Write(«,»)
objOutputFile.write(«EntSpecific»)
objOutputFile.Write(«,»)
objOutputFile.write(«generic»)
objOutputFile.Write(«,»)
objOutputFile.write(«Specific»)
objOutputFile.Write(«,»)
objOutputFile.write(«OID»)
objOutputFile.Write(«,»)
objOutputFile.write(«Source»)
objOutputFile.Write(«,»)

do while not objInpoutFile.AtEndOfStream
lineread = objInpoutFile.ReadLine()

If ((Left(lineread,2)) = «>>») Then
‘if line starts with >>, start a new line and put the time stamp from the content
datestr = Left(lineread,25)
timestamp = Right(datestr,8)
objOutputFile.write(vbCrLf)
objOutputFile.Write(timestamp)
objOutputFile.Write(«,»)

elseif ((Left(lineread,1)) = «») Then
‘if bliank line, skip the line

else
‘write the line to file with comma at the end
objOutputFile.Write (lineread)
objOutputFile.Write («,»)

‘If Err.Number <> 0 Then
‘ ‘error handling:
‘ WScript.Echo «Line: » & x & «Error no: » & Err.Number & » Srce: » & Err.Source & » Desc: » & Err.Description
‘ Err.Clear
‘End If

Content of File that throws error (line that is underlined):

>>>> 23 Apr 2013 00:13:08 — Unhandled (Source not monitored)

SNMPv2 Trap (enterpriseSpecific = 101)
Generic: 6
Specific: 101
Enterprise Oid: 1.3.6.1.4.1.33386
Source: x.x.x.x
Community: xxxxx
Variable: 1.3.6.1.2.1.1.3.0
Type: Time Click
Value: 0
Variable: 1.3.6.1.6.3.1.1.4.1.0
Type: OID
Value: 1.3.6.1.4.1.33386.1.101
Variable: 1.3.6.1.6.3.1.1.4.3.0
Type: OID
Value: 1.3.6.1.4.1.33386
Variable: 1.3.6.1.4.1.33386.2.11
Type: String
Value: High VM Memory Utilization
Variable: 1.3.6.1.4.1.33386.2.1
Type: String
Value: Memory utilization of the VM over 70% (xxxxxxx)
Variable: 1.3.6.1.4.1.33386.2.2
Type: String
Value:
Variable: 1.3.6.1.4.1.33386.2.4
Type: String
Value: Warning
Variable: 1.3.6.1.4.1.33386.2.7
Type: String
Value: Any
Variable: 1.3.6.1.4.1.33386.2.3
Type: String
Value: 1.0
Variable: 1.3.6.1.4.1.33386.2.5
Type: String
Value: NULL
Variable: 1.3.6.1.4.1.33386.2.6
Type: String
Value: NULL
Variable: 1.3.6.1.4.1.33386.2.12
Type: String
V alue: The memory utilization of the VM is sustaining over 70%. This could indicate excessive workload activity. Consider the active links below for further drill down.
Variable: 1.3.6.1.4.1.33386.2.8.1.2.0
Type: String
Value: SVHOF-FS05
Variable: 1.3.6.1.4.1.33386.2.8.1.1.0
Type: String
Value: 5fabc69c-1509-41e6-92b8-759d20924018
Variable: 1.3.6.1.4.1.33386.2.8.1.3.0
Type: String
Value: VirtualMachine
Variable: 1.3.6.1.4.1.33386.2.8.1.4.0
Type: String
Value: 74.86
Variable: 1.3.6.1.4.1.33386.2.8.1.10.0
Type: Integer
Value: 0

Answers

Open the file in notepad and save it back as ANSI. Same name- same location.

At a prompt type: WSCRIPT //H:cscript

Now — from a CMD prompt run the same VBS again.

I go some clue in the following article,. Hopefully able to get it resolved.

Just tri-state the file in the OpenTextFile.

fso.OpenTextFile(filename, 1 False, -1) ‘ Opens Unicode file.

If the file is not little endian you will have to convert it.

Start by removing ‘On Error Resume Next’ and handle all errors. The error you are getting is because you are ignoring earlier errors. You cannot blanket disable error handling.

A quick look says that the file cannot be converted to a CSV unless you skip the first 10 lines.

The CSV will have only three columns — variable,type,value.

You could prepend these to each line and get a de-normalized CSV:

Generic: 6
Specific: 101
Enterprise Oid: 1.3.6.1.4.1.33386
Source: x.x.x.x
Community: xxxxx

IN all cases your conversion method will not work.

Thank you jvr for taking time to respond to my post.

Not sure why you are saying that its not going to work. I mentioned that it works for most of the log files I convert to CSV format. However, for some files, it throws the error. If I remove «on error resume next», I get the same error, «invalid procedure call or argument» on line 64, which is

in the above code (last else section).

Also, what I just discovered that if I open the same log file (which is throwing error) in notepad++ and select all the contents and copy in notepad and save a new log file, it works! So, it got to be some special character or something in the log file which VBscript is unable to read. Not sure how do I catch or skip that particular line (it really doesn’t matter much for me if I need to skip a few lines out of half a million lines in a log file).

There is no line that you can read from a file that you cannot write to a file. YOu need to put in trace statements to find the line. I suspect the line is null.

Change code to look like this:

This will force the null to a string.

You cannot use parens in VBSCript when not returning a value.

did not work. Still same error.

Further debugging throws this error

Error no: 13 Srce: Microsoft VBScript runtime error Desc: Type mismatch

This error is thrown when trying to write line 153 in the output file. This equate to the following line in the source log file.

Value: The memory utilization of the VM is sustaining over 70%. This could indicate excessive workload activity. Consider the active links below for further drill down.

did not work. Still same error.

How do you know that is the line causing the error?

Further debugging throws this error

Error no: 13 Srce: Microsoft VBScript runtime error Desc: Type mismatch

This error is thrown when trying to write line 153 in the output file. This equate to the following line in the source log file.

Value: The memory utilization of the VM is sustaining over 70%. This could indicate excessive workload activity. Consider the active links below for further drill down.

Try putting a few messages boxes around that code printing the variable type and value.

msgbox vartype(lineread) & » » & lineread

or to make it easier by only displaying the message box after the 150th time through the loop.

count=count+1:if count > 150 then msgbox vartype(lineread) & » » & lineread

David — in the interest of a speedy solution can we not get too many of us asking for the OP to do things.

I am trying to get the issue clearly defined. That was the motivation behind my last request.

To add to my request I will add the particle of code:

This will prove out the error similar to your request but it is cleaner.

We must prove that this is the line of code. I very much doubt that the error message reported is coming from this line. from this script.

Getting closer to track the issue! Thank you both jrv and David.

When I put the lineread in msgbox as well as the error handling as specified by jrv, I see the following.

—————————
Windows Script Host
—————————
Script: D:AshscriptsvbFileHandleScriptReadFileWriteCSV v2.vbs
Line: 85
Char: 5
Error: Object required: ‘objOutputFile’
Code: 800A01A8
Source: Microsoft VBScript runtime error

The first few lines of log file as per below. So, reading the very first line seems to be the root cause of the problem!

>>>> 23 Apr 2013 00:02:49 — Unhandled (No matching rule)

SNMPv1 Trap (egpNeighborLoss)
Generic: 5
Specific: 5
Enterprise Oid: 1.3.6.1.6.3.1.1

else
‘write the lineread to file with comma at the end
msgbox «Line: » & x & » » & «Vartype » & vartype(lineread) & » » & lineread
objOutputFile.Write lineread
if Err.Number <> 0 Then
MsgBox «Error on write:» & Err.Number
MsgBox Err.Description
End If
On Error GoTo 0
objOutputFile.Write («,»)

Youy did not doi what I asked. In fact you did exactly what I didn’t want you to do so all of the information is invalid, What you did will always give the same output no matter what is causing the error,

We need to lock down the exact source of the error.

When I said I wanted the code I meant ALL of teh code, We cannot help if you keep passing out only bits of information.

This piece of code:

else
‘write the lineread to file with comma at the end
msgbox «Line: » & x & » » & «Vartype » & vartype(lineread) & » » & lineread
objOutputFile.Write lineread
if Err.Number <> 0 Then
MsgBox «Error on write:» & Err.Number
MsgBox Err.Description
End If
On Error GoTo 0
objOutputFile.Write («,»)

Is NOT what I asked you to do.

else
‘write the lineread to file with comma at the end
On Error Resume Next
objOutputFile.Write lineread
if Err.Number <> 0 Then
MsgBox «Error on write:» & Err.Number
MsgBox Err.Description
End If
On Error GoTo 0
objOutputFile.Write («,»)

Remove all other copies of On Error Resume Next anywhere but at that one location.

This progrma line needs to be in tight pairs. Arbitrary use makes debugging nearly impossible. Do not do What David suggested as it will not help us find a solution. We need to find each piece in order. First we prove which line is generating the error. After that we diszcover why. If I had you code and file I could find the answer in l,ess that 2 minutes. I am relying on you to be the eyes, ears and hands and do what my brain is telling you is correct. I have been debugging code in a dozen langauges for more than 30 years. I ALWAYS get my bug. I always get it quickly. That is why they pay me the big bucks, Just like the big guys uptown. ( Well maybe like Wyatt Earp.. or maybe like Bat Masterson)

Источник

Понравилась статья? Поделить с друзьями:
  • Microsoft vbscript runtime error 800a000d
  • Microsoft vbscript runtime error 800a0005
  • Microsoft vbscript compilation error expected end of statement
  • Microsoft teams ошибка 4с7
  • Microsoft teams код ошибки caa50024