Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What causes VB6 "Run-Time Error '5': Invalid Procedure Call or Argument"

In VB6, users occasionally receive this error and I am unable to reproduce it.

Run-Time Error '5': Invalid Procedure Call or Argument

I am referencing the "MSWord 10 Object Library" and sometimes this error occurs at some point after the application has opened MSWord 2002. However, this app has referenced the MSWord 10 Object Library for years, and this error just started occurring in the last few months.

The code is shelling the app using the following:

Dim app As Word.Application = GetObject("", "Word.Application")

I am assuming I have introduced a bug somewhere, but no idea what might be causing it. The error does not occur very often and cannot be reproduced by a user when I am standing there. The error forces the app to totally shut down.

Users are running Windows XP. The user reporting the issue the most is running the app thru Citrix. There are 350 total users, about 100 use the app thru Citrix.

Any ideas on how fix the error?

like image 636
user52212 Avatar asked Mar 16 '10 13:03

user52212


1 Answers

From memory with VB6 (now using .net) this can point at the users machine being low on memory or that your code has been unable to get a handle for the word app.

If you are unable to produce the problem within Visual Studio and unsure which line in your code is causing the issue you are probably best off adding an error handler around the code that is causing the problem.

At the top of the sub that has problems put

   On Error GoTo MyErrorHandler

and then at the bottom put

   On Error Goto 0
   Exit Sub
MyErrorHandler:
   MsgBox "Error " & Err.Number & " (" & Err.Description & ") at line " & Erl

Rather than using a MsgBox as I have here consider writing down to a file instead. Also for Erl to work correctly considering numbering each of your lines.

For VB6 a great plugin is MZ tools link which will help you add the error handling and line numbers really easily

like image 89
CResults Avatar answered Sep 21 '22 12:09

CResults