Invalid procedure call or argument microsoft vbscript runtime error

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

Читайте также:  Gpsmap 60csx версия прошивки

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.

All replies

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.

Читайте также:  C error expression must have pointer to object type

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:\Ash\scripts\vb\FileHandleScript\ReadFileWriteCSV 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!

Читайте также:  Gta san andreas multiplayer runtime error

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

Источник

Smartadm.ru
Adblock
detector