Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Visual Basic 6 Program Quits without any runtime error

Posted on 2011-03-09
Medium Priority
Last Modified: 2012-05-11
Dear Experts,

i have a weird Problem going on since i last compiled a program of mine..
on many computers... if an error occurs, i no longer get runtime errors.. the executable simply gets killed... and disappears..  (it doesn't remain in memory)

if i repeat the same steps to reproduce the error in the visual basic 6 ide, then i get the runtime error, and i'm able to fix it..

however, sometimes my clients call me and say that the program disappears.. and actually they don't know what to say, because they don't have neither a screenshot of the error, nor the error msg.. so it's hard for me to debug the version..

any hints?

p.s. it's happening often, with many clients.. and on different machines.. so it's not a certain machine or operating system issue...

i've seen it.. on windows xp sp3, windows xp sp2, and windows 2003 server sp1

i appreciate your help,

Question by:Dany Balian
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 76

Expert Comment

ID: 35089427
To start with the obvious: do you have any 'On error resume next' statements or similar in the code?
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 35089573
VB6 apps with subclassing can present these kinds of mysterious bugs too...got any of that?
LVL 16

Expert Comment

ID: 35092540
We need details of your error handling.  If you don't do it correctly, or violate some unwritten rules, odd things like this can happen.

As an example, any "On Error" statement clears the contents of Err.  If you (foolishly) include an error handler in the 'Terminate' event of an object (class or form) then the contents of the global Err object will be destroyed if an instance of that object goes out of scope (automatically invoking its Terminate Event) as an Error gets sent up the calling stack.

Here's an example of code that shows this bug:

Public Sub Class1_Terminate()
    On Error Resume Next
    'Clean up code here
End Sub

Public Sub Main()
  On Error Goto DisplayError
  Call MainSub()
  Exit Sub
  MsgBox( "Err# " & cstr(Err.number) & " - " & Err.description )
End Sub

Public Sub MainSub()
  Dim C as Class1
  Set C = new Class1
  Err.Raise( 5, "Some Error")
  MsgBox "This line of code never executes"
End Sub

What happens is that Main calls MainSub that creates an instance of a Class1 object.  When the error is raised in MainSub, the error is sent to the error handler in Main... but on the way out of MainSub, the Class1 Terminate event gets invoked.  The On Error Resume Next clause clears the contents of Err.  Once the Terminate event is complete, the error is sent to the Main Error handler "DisplayError", where the following message is displayed in a message box:
    Err# 0 -
because Err.number is 0 and Err.description is blank (even though you explicately raise error # 5 with some made-up description).

I could (and would if VB wasn't such a dying language) write an artical on the proper way to keep control over errors.  In this sort of situation, what I've learned to do is create a bunch of Error handler helper functions.

For example, I've defined in my code a Type by the name TypeError where the elements of the type match the elements of the Err object.  I then have Terminate Events that look like this:

Public Sub Object_Termnate
Dim theError as TypeError
    ERROR_IfActiveThenSave( theError )
    On Error Resume Next
    'Execute clean up code
    ERROR_IfSavedThenLoad( theError )

The function ERROR_IfActiveThenSave() simply looks to see if Err.number <> 0.  If it is, then it copies the contents of Err to theError.

The function ERROR_IfSavedThenLoad() simply looks to see if theError.number <> 0.  If it is, then it copies the contents of theError to Err.

So if there is an error actively being passed up the call stack when this Terminate event is invoked, the contents of Err are copied to theError, the On Error clause clears the content of Err, the Terminate event executes without raising any errors, and the contents of theError are copied back into Err.
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!

LVL 10

Expert Comment

ID: 35095622
1. Are you encrypting it? Some encryption programs will screw it up so it does that. So you need to change the encryption options.

2. What is the specific runtime error you are getting within the IDE, and please post the code snippet here.

LVL 11

Author Comment

by:Dany Balian
ID: 35100696
thanks all for your participation:

nothing has changed in my code! that's the weird part...

in my ide, errors are normal errors... like invalid use of null while reading from the database, or picture not found in res file.. or whatever.. or invalid parameter type sent to a report!

* i have error handling in all my program...

i use sometimes on error resume next, and catch it on the next line!
or on error goto err_handler: then i handle the error accordingly

* no encryption used in my code!

* regarding classes: yes i have classes and i have custom activex controls in my project.. but haven't changed anything in them lately... anyways, to test ur point of view... i have quoted all "on error resume next" statements.. still same thing occurs..

another question: is there anyway to create a catchall error procedure??


Expert Comment

ID: 35107130
* I don't think "on error resume next" could cause this sort of problem..
* If the App terminates without any message - are you sure there isn't an inadvertent "Unload Me" on a form that is inadvertently the "Last Form Standing"?
* Does this behavior occur on several PCs?

* Windows service packs or Patches are famous for causing new error situations to occur!
(specially with 'custom activex controls')
* Can you temporarily replace the functionality of the activex controls with a normal code module?

Expert Comment

ID: 35107695
A couple of hints:
1) Look at windows application log, sometimes a VB6 app may "disappear" caused by application exceptions (e.g. access violations). In these cases you will find related entries.
2) Check if Windows is configured to disable error reporting: Control panel, System, Advanced, Error Reporting. Make sure you have selected Enable error reporting for Programs (and Windows as well)
LVL 11

Author Comment

by:Dany Balian
ID: 35108071
- the behavior occurs on several pcs - no recent service packs installed (not even in the past 6 months) (updating is disabled)
- any error that occurs in any form forces the program to disappear without any warnings!
- example: i added a new command button to a form (any form):
sub command1_click()
dim i as integer
end sub

this should give overflow! it doesnt, it just quits the program...

- error reporting is not disabled: it's actually enabled for all programs..
- nothing shows in any of the event groups (system, application, ...)

gonna check my custom controls if they contain anything suspicious and will try also to remove them if i can...


Accepted Solution

BrianVSoft earned 1500 total points
ID: 35108471
You could try compiling a new simple app - that might "overflow" correctly.. Then gradually add the components of your 'troubled' app until it starts to fail..
Or.. You could try compiling on a colleagues PC that has a different copy of VB6 installed?
Or compile on a PC where you can re-install VB6 from original CDs and re-download SP6..
LVL 11

Author Comment

by:Dany Balian
ID: 35108799
already tried recompiling on 2 different computers..
i will try ur strategy of gradually adding components until the system overflows correctly << hehe, i like the expression!

will let u know what happens although nothing has changed in the codes of the components since last 10 builds!
LVL 11

Author Comment

by:Dany Balian
ID: 35142778
i have some updates! and i have solved the problem but in a weird way, if someone can explain so that i solve my problem in a better way i would be more greatful..

here's what i've done:
- first i've removed completely all my custom user controls and replaced them with some similar native components..
and the project run normally (runtime errors produce normal msgboxes with error descriptions and error numbers)
- i created a new activex control project, and put all my usercontrol in it, compiled the ocx, and referenced it in my project.. and reverted all the native components with my custom controls..  and the project still runs as expected (normal  runtime errors)

finally, thinking that something weird is happening, i removed the reference of the ocx from my project, and i put back the custom controls to the project.. and the problem reappeared! (on errors, the exe just disappears with no runtime error)

any hints about what's going on?


Expert Comment

ID: 35143003
That actually isn't weird.. Our companies "elder VB guys" all remember situations like that..
It could also be that a virus has damaged the ocx? Do you have an old copy in an archive you could dig out and compare bytewise? You might find a few hundred bytes are different.
In any case, none of our VB guys think thats unusual - just typical of microsofts platform.
LVL 11

Author Closing Comment

by:Dany Balian
ID: 35305308
didn't solve the problem the way i wanted, but guided me in the right way to know which component was making the error! i converted it into ocx and merged it in my project, but still unable to use it when i added to my project as a user control

Featured Post


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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

618 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