Solved

VB  .EXE Problem.

Posted on 1998-11-17
17
154 Views
Last Modified: 2010-05-03
I get Error 5 (Invalid Proc Call or Argument) when running an exe file, but not when am running the debug version. Happens on a MSGBOX statement(no problem when that lines commented out). Occurs in a TextBox_LostFocus of an MDI child. The same line works in other parts of the same program. Would be grateful for any help.
0
Comment
Question by:jkeogh
  • 7
  • 4
  • 3
  • +3
17 Comments
 
LVL 2

Expert Comment

by:kswinney
ID: 1445271
Could you post the offending code segment?  It may be what you're trying to pass to the function rather than the function itself.
0
 

Author Comment

by:jkeogh
ID: 1445272
Private Sub txtNACE_LostFocus()
    MsgBox "Entry information complete", vbOKOnly, "Information"
End Sub

Thats all thats in the procedure.
By the way I should have mentioned that I'm running VB5.
 
0
 
LVL 1

Expert Comment

by:yfang
ID: 1445273
Try to use something like:

MessageString = MsgBox ("Entry information complete", vbOKOnly, "Information")

Message box is a function, not a subroutine. One of the best ways to call a function is to assign it to a variable.
0
 

Author Comment

by:jkeogh
ID: 1445274
I tried this and it has made no difference to my problem. I accept yfang's point that I was calling MSGBOX in a 'lazy' way but I have done the same in other programs, and in other parts of the current program without any problem. It is only this
particular MSGBOX call which causes me the problem. It is definitely this line as when I comment it out I have no crash.
Thanks for your interest, yfang, and please re-reply if you
have any other suggestions.
0
 
LVL 1

Expert Comment

by:Staplehead
ID: 1445275
jkeogh,

just out of curiosity...

what happens if you change the line of code to its non-"lazy" form:

    call msgbox ...

???

Larry
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1445276
Are you using doevents somewhere in this code?
0
 

Author Comment

by:jkeogh
ID: 1445277
I narrowed this problem down a bit further. In FormLoad I make a
call to a sub called AbleControls which sets the enable property of all controls on my form to True or False (in this case False) Those controls which have no enable property are excluded by use
of ifs. When I comment out the call to this module I have no problems with my MSGBOX call later on. This suggests to me that
that when when running the .EXE as opposed to the debug version,
there is some extra control that I am disabling.
Here is the Subroutine.

Sub AbleControls(F As Form, TrueFalse As Boolean)
    Dim lclCtl As Control
    Dim lclObj As Object
    Dim lclStrCtlType As String
   
    'Disable all controls on the form
    For Each lclCtl In F.Controls
        lclStrCtlType = TypeName(lclCtl)
        If lclStrCtlType = "Menu" Then
            'Do nothing
        ElseIf lclStrCtlType = "TabStrip" Or _
               lclStrCtlType = "SSTab" Then
            'Do nothing
        ElseIf lclStrCtlType = "Toolbar" Then
            'Do nothing
        ElseIf lclStrCtlType = "ListView" Then
            'Do nothing
        ElseIf lclStrCtlType = "CommonDialog" Then
            'Do nothing
        ElseIf lclStrCtlType = "Line" Then
            'Do nothing
        ElseIf lclStrCtlType = "CrystalReport" Then
            'Do nothing
        Else
            'We are OK to set the enabled property
            lclCtl.Enabled = TrueFalse
        End If
    Next
End Sub

P.S In reply to Mirkwood and StapleHead, I am not using DoEvents
and the problem was still occuring no matter what way I was calling MSGBOX.
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1445278
Why not put all controls on a frame and disable the frame. This will have the same result.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:jkeogh
ID: 1445279
Mirkwood,
If possible I'd prefer not to do as you're suggesting as I have about 200 forms on this system, and I'd have to put a frame on
each of them, new source code etc. Ideally I'd like to put a fix
into the AbleControls subroutine above to fix any problem.
Its unfortunate that I waited till I basically had my system
finished before trying to make an .EXE. This is the first VB
system I've done and I'll take on board the frames thing next time.
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1445280
On error resume next will most likely get rid of your problem
0
 

Author Comment

by:jkeogh
ID: 1445281
I placed 'On Error Resume Next' before the MSGBOX call but I still have the same problem. I tried checking for err.number = 5 and using err.clear but I still always get the crash.
0
 
LVL 1

Expert Comment

by:Staplehead
ID: 1445282
jkeogh,

ok... what you're trying to do in ableControls is set the Enabled property for all controls EXCEPT Menus, TabStrips, etc...

If you're thinking that you're setting the Enabled property of something that you shouldn't be, then let's look at your approach from another perspective.  Exactly which types of controls DO you want to go after?  If you enumerate them in an if/elseif or case, then you might not hit a control which you don't want, and not get the error...

Larry
0
 
LVL 14

Expert Comment

by:Matti
ID: 1445283
Hi!
There are probaply some parts in your program that can't be complied by the VB complier.

MsgBox "Entry information complete", vbOKOnly, "Information"

There is someting in this sentence that VB did not complie proberly.
Try first what is efect of compile to P-code/ Native code.

If this don't give proper combilation then try this:

Replace vbOKOnly whit 6&

This will cause Vb not to use constant value in here,
if the problem is in the VB compilation part, it will not
need to get this constant from the library file.



0
 

Author Comment

by:jkeogh
ID: 1445284
Firstly Matti. I tried the two things suggested and neither made
any difference.
Secondly Staplehead. What you said made sense. I changed AbleControls to only operate on the types of controls that I wanted Enabled/Disabled. These being TextBoxes,Commandbuttons,
ComboBoxes and Labels. I still had the problem. I then commented out each of them in turn and found that the problem was only occuring on ComboBoxes. I moved my disabling of ComboBoxes into
my main program and found that my problem is now this....
The MSGBOX line crashes only when I have disabled the Combo Box on my form. If I comment out that line, everythings fine.
Again just to emphasize that this occurs only when running the
EXE. Works perfectly OK doing a normal debug.
0
 
LVL 1

Expert Comment

by:Staplehead
ID: 1445285
some questions for you:

how are txtNACE and your combo box related? does data flow between them, based on user interaction?

are you certain that it's at the *msgbox* line that you're crashing? is it possible that it's crashing before that line is executed?  (try some sort of debugging, like changing the color of a control or something *immediately* before the msgbox line.)

are you attempting any manipulation of the combo box in the "vicinity" of your execution of the msgbox command? take a look at statements which "touch" the combo box variable.  are any properties accessed or altered when the combo box is disabled, sometime just before the txtNACE_LostFocus event handler is called?

are you doing any OOP? are there any objects/classes at work here? (i'm trying to determine whether any other code is executing that might be easy to overlook..)

finally, are you willing to post or email your code?

Larry
0
 

Author Comment

by:jkeogh
ID: 1445286
Larry S.
I think I have this solved. Its ties in with your third point above though I dont understand in totally yet (I've only been
doing VB about 4 weeks)
I have some command buttons which get enabled, disabled or setfocussed depending on whether TxtNace is empty,non-empty or
full, with a check after every keystroke (txtNace_Change).
It seems that when I tabbed off the Nace, code in one of the CommandButtons_GotFocus was going off before txtNace_LostFocus.
I dont really understand it as it doesnt happen when I'm debugging.
Anyway I made some changes to the order of source code and things
seem OK. As you put me on the right track, if you send a solution
thingummy to me, I'll accept it and give you the points.
Thanks to yourself and everyone for their help and I'm sure I'll
talk to you again,
John Keogh.


0
 
LVL 1

Accepted Solution

by:
Staplehead earned 200 total points
ID: 1445287
actually, getting the order of event firing down is, in my opinion, one of the most frustrating parts of learning VB.  just when you think you've got it down cold, something like that sneaks up and bites you...

Larry
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

744 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

10 Experts available now in Live!

Get 1:1 Help Now