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.

Posted on 2004-11-26
Last Modified: 2011-08-18
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.
Question by:RDWINDLEY
    LVL 55

    Expert Comment

    by:Jaime Olivares
    If you don't post your code, we can't "guess" the answer.
    LVL 18

    Expert Comment

    Do you get the error from the exe on the same machine as the development environment or is it just on other machines?

    Author Comment

    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.
    LVL 32

    Assisted Solution

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

        'Error handler
        MsgBox "Error in Form_Load()" & vbcrlf & "Number " & err.number & " " & err.description
    End Sub
    LVL 18

    Accepted Solution

    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.

    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

        'Error handler
        MsgBox "Error in Form_Load()" & vbcrlf & "Number " & err.number & " " & err.description & " at line:" & erl
    End Sub
    LVL 7

    Assisted Solution

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

    LVL 11

    Assisted Solution


    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Introduction This article makes the case for using two modules in your VBA/VB6 applications to provide both case-sensitive and case-insensitive text comparison operations.  Recently, I solved an EE question using the LIKE function.  In order for th…
    The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now