Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Show won't run Load in special cases - puzzling 1

Status
Not open for further replies.

Devin

Programmer
Dec 17, 2001
42
US
There should be an award for most bizarre errors, for surely I would win. I spent a whole day pulling my hair out over this, but now I must seek help. Here we go...

I have a very simple program that has a form with something like the following:

Code:
Private Sub someButton_Click
  begin
    anotherForm.Show 'anotherForm was not loaded previously
    Unload Me 'there is no code in the Unload method
  end

Of course, upon executing anotherForm.Show, the anotherForm_Load method should run, and then the current form should disappear. This is exactly what happens when I run in debug mode or directly from the executable (on the development machine). I have confirmed it with both breakpoints and run-time messages.

However, on the test machine, run-time debugging messages indicate that, although anotherForm.Show is executed, the first line of anotherForm_Load never is! It just skips that part, goes right to Unload Me, closes the original form and, seemingly, the whole program. I say seemingly, because, some minimal bit of it stays alive and can be seen in the task manager. (When I first noticed that, I figured anotherForm was loaded but hidden, until I put in the run-time debugging messages and learned that it's Load method had never begun.)

It should be noted that I have 3 other nearly identical programs that perform this simple maneuver properly, in all cases.

Generally speaking, can anyone think of a situation in which newForm.Show would not cause the newForm_Load method to run, assuming that newForm is not already loaded?

I did read the excellent, recent post, "It's a Forms life...," by TheVampire. It taught me a lot but gave me no insight into what is happening here.

Now, as I sit and wait for help from you experts on this tough one, I'll see if I can answer some of the easier questions that are posted this morning. Thanks for any advice you can offer.
 

Remove "begin" and "End" form your code. [/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Sorry-- that was a typo -- of course I do not have begin, and the method ends in "end sub." That is not the problem. Sorry for the confusion.
 
You might try placing a DoEvents after the .Show Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
What happens if you just use:

Load anotherForm

Does the code in the Load event execute? Step through it.

Also, is something else being called in the Form_Load or Form_Activate that may be causing it to unload?
Watch out for setting the values of some control where one of it's events may be executing and causing the form to unload.

And, what is in the Declaration section of the form class?

Lastly, try declaring a form variable and then loading it:

Dim frm As anotherForm
Set anotherForm = new anotherForm

Load frm
frm.show

again, step through it. [/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Thanks but...what was it? [/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
That star was only for your effort. It will take me some time to try all these ideas. I suppose it would have been proper to save the star for when I've solved it. I'll let you know when I do.

Thank you, all, for such quick responses.
 
So, I've finally learned something new! I tried calling Load separately from Show and putting DoEvents between everything, but that did not help. Then I tried to create an Initialize method to see if at least that was being called via Load. YES, it is. The msgbox I put in (the only contents of Initialize) does appear. Then I Load the form, but it never gets to the first line of the Load method, as before. Remember, I can't reproduce this on the development machine, so I'm learning all this with msgboxes, compiling between each test -- so arduous! I must assume (from what I learned from vbconlifecycleofvisualbasicforms.asp, cited above) that Initialize is failing to create some object and, thus, making Load impossible, though the absence of any run-time error message is very disconcerting.

Can anyone think of a deeper way to debug this? Is there a way to step through and monitor the initialize process. Is there a log? Perhaps I can manually create each object, instead of letting Initialize do it automatically, and put msgboxes between each one to see which fails. I have no idea how one would do that, except that it would take a hell of a lot of new code. I'm just trying to extend the "decomposition" debugging paradigm, but I don't think the nature of VB will allow me to go any deeper.

I think I should also investigate control registration issues, because of the odd fact that it works fine on the development machine (in VB or compiled), as I said above.
 
Given the information provided in your last post, I would lean towards a control registration issue. The very fact that its not failing on the development machine implies that its not in the code. If the code were bad, then it fail on all machines. Therefore, we investigate environmental related problems.

First question - how did you install the program on the non-development machine? Did you simply copy the exe, or did you use any installation package. The installation packages look for depdenancies, and include those controls and have them registered as part of the install process. If you are not using such an install package, then I would do that first and see if the problem goes away. If you are, then you may have a corrupted control on the other machine, or a bad registration of that control.

To find the offending control, start removing 3rd party controls - one at a time - from anotherForm. If it is a control problem, then once that control has been removed, then it should start working. If the control is already on the other machine, you might try unregistering it, and deleting it, then re-install using an installation package. You may be able to copy that control and manually register it. Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top