Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 168
  • Last Modified:

VB .EXE Problem.

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
jkeogh
Asked:
jkeogh
  • 7
  • 4
  • 3
  • +3
1 Solution
 
kswinneyCommented:
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
 
jkeoghAuthor Commented:
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
 
yfangCommented:
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
jkeoghAuthor Commented:
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
 
StapleheadCommented:
jkeogh,

just out of curiosity...

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

    call msgbox ...

???

Larry
0
 
MirkwoodCommented:
Are you using doevents somewhere in this code?
0
 
jkeoghAuthor Commented:
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
 
MirkwoodCommented:
Why not put all controls on a frame and disable the frame. This will have the same result.
0
 
jkeoghAuthor Commented:
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
 
MirkwoodCommented:
On error resume next will most likely get rid of your problem
0
 
jkeoghAuthor Commented:
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
 
StapleheadCommented:
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
 
MattiCommented:
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
 
jkeoghAuthor Commented:
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
 
StapleheadCommented:
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
 
jkeoghAuthor Commented:
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
 
StapleheadCommented:
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 4
  • 3
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now