• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5352
  • Last Modified:

Runtime Error 5 occurs when running compiled executable. Does not occur when running program in the IDE. Have checked Mid$() statements and found no problems.

I'm using VB6 with Service Pack 6 running on XP or Windows 2000 (problem occurs on both platforms).  I'm attempting to write a program that runs fine in the IDE, however, when I compile it and try to run the .EXE file, I get a Runtime Error 5, Invalid Procedure Call or Argument.  I've checked the program for a misprogrammed Mid$() statement and don't see anything amiss.  Any ideas on what might be wrong or how I can trap this error?  Is this a platform specific error or a problem with V.B. Serv. Pack 6?  I need a solution as soon as possible because I've got several machines not working now because of this at the plant where I work.
0
RDWINDLEY
Asked:
RDWINDLEY
4 Solutions
 
Jaime OlivaresCommented:
If you don't post your code, we can't "guess" the answer.
0
 
JR2003Commented:
Do you get the error from the exe on the same machine as the development environment or is it just on other machines?
0
 
RDWINDLEYAuthor Commented:
Thanks JR2003,  I get the error when I run the EXE on any of the other machines and also the machine where my development environment resides.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Erick37Commented:
>>Any ideas on what might be wrong or how I can trap this error?<<

You can trap the error using standard VB error handling.  In each procedure, place an error handler similar to the following example.  First pinpoint which function is erroring, then try to find which line is throwing the error.

Private Sub Form_Load()

    On Error Goto ERR_FORM_LOAD

    '...
    Text1.SetFocus '<< will cause error 5 because control is not yet visible
    '...

    Exit Sub

ERR_FORM_LOAD:
    'Error handler
    MsgBox "Error in Form_Load()" & vbcrlf & "Number " & err.number & " " & err.description
End Sub
0
 
JR2003Commented:
If you add line numbers to your code you can also report the line number where the error occured in the error trap using the 'erl' variable.
You can use an addin tool like mztools for automatically adding line numbers.
e.g.:

Private Sub Form_Load()

1000    On Error Goto ERR_FORM_LOAD

    '...
1010    Text1.SetFocus '<< will cause error 5 because control is not yet visible
    '...

1020    Exit Sub

ERR_FORM_LOAD:
    'Error handler
    MsgBox "Error in Form_Load()" & vbcrlf & "Number " & err.number & " " & err.description & " at line:" & erl
End Sub
0
 
HoweverCommaCommented:
One thing that no one has mentioned that very well could be the culprit is a compiler option...

If you have Code optimised for speed or size VB can can give you a big headache.
During compilation expressions may not evaluate properly. Even those that you explicitly assign precedence operators to.
This once caused me days of grief, never again.
http://support.microsoft.com/default.aspx?scid=kb;en-us;191616

I don't know how Billy can live with himself charging for this. Damn thing has been like that through 2 versions and 10 or so service packs...

Try this, even if you think your code is not affected by it.

0
 
cool12399Commented:
Ah,

Chances are you are passing in invalid values,i.e., somewhere it might expect an int (you've explicitly declared it as such), and yet you are using a long. One way of easily isolating it is by putting an 'on error goto errhandler:' and in the errhandler say 'error in procedure ABC'.

P.S. please close the question & award the points, thanks!

Also, here is some additional info that may help you:
---------------------------------------------------------------------------------------------------------
Some part of the call can't be completed. This error has the following causes and solutions:

An argument probably exceeds the range of permitted values. For example, the Sin function can only accept values within a certain range. Positive arguments less than 2,147,483,648 are accepted, while 2,147,483,648 generates this error.
Check the ranges permitted for arguments.

This error can also occur if an attempt is made to call a procedure that isn't valid on the current platform. For example, some procedures may only be valid for Microsoft Windows, or for the Macintosh, and so on.
Check platform-specific information about the procedure.

For additional information, select the item in question and press F1
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now