Solved

Visual Basic 6 Program Quits without any runtime error

Posted on 2011-03-09
13
411 Views
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,

cheers,
0
Comment
Question by:Dany Balian
13 Comments
 
LVL 76

Expert Comment

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

Expert Comment

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

Expert Comment

by:HooKooDooKu
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
DisplayError:
  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.
0
 
LVL 10

Expert Comment

by:cool12399
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.

Thanks.
0
 
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??

0
 
LVL 5

Expert Comment

by:BrianVSoft
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?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 3

Expert Comment

by:rafunk
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)
0
 
LVL 11

Author Comment

by:Dany Balian
ID: 35108071
@Brian:
- 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
i=999999
end sub

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

@rafunk:
- 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...

0
 
LVL 5

Accepted Solution

by:
BrianVSoft earned 500 total points
ID: 35108471
Wow!..
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..
0
 
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!
0
 
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?

0
 
LVL 5

Expert Comment

by:BrianVSoft
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.
0
 
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
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

747 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

13 Experts available now in Live!

Get 1:1 Help Now