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.
RDWINDLEYAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jaime OlivaresSoftware ArchitectCommented:
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.