Results 1 to 10 of 10

Thread: 2nd Form Load interupted by 1st forms calling event

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2012
    Posts
    15

    2nd Form Load interupted by 1st forms calling event

    Hello Everyone,

    Going a little crazy looking for an answer.

    There are two forms, Search and View. Search is the startup form and has a button linking to View. My problem is that my view form does not complete it's FormLoad event when called from Search, it however behaves fine when made the startup form, bypassing Search altogether. I have tried several OnClick events for my button in Search but nothing seems to make a difference. Currently I am using:
    View.Show()
    Me.Hide()

    When I try to debug, the program counter begins cycling through all the form load events of View, calling a few Subroutines but on the last Subroutine it breaks away early and ends up at Me.Hide() in the button event. Once the button event finishes the debug stops and the form is partially loaded.

    From what I can tell it has nothing to do with the subroutine that it halts on. Anyone farmiliar with this issue and have any advice?

    Thanks a lot!

  2. #2
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: 2nd Form Load interupted by 1st forms calling event

    on the last Subroutine it breaks away early and ends up at Me.Hide() in the button event.
    Maybe an error occurs in that sub but you don't catch it properly.

    To know what's going on,
    1- Put the cursor at the first line of the last sub and press F9 to add break point.
    2- Run the program
    3- When the program stop, continue press F8 to see which line cause unexpected break.



  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2012
    Posts
    15

    Re: 2nd Form Load interupted by 1st forms calling event

    Thanks but I did step through many many times. It seems to be a matter of timing rather than a particular piece of code. If I move code around an add code, remove code, it's breaks at different places everytime, never the same place. I feels like it shows the form, activates the events, executes some of the event before it is pulled away to deal with the button event.

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: 2nd Form Load interupted by 1st forms calling event

    Wrap the code in the Load event in a Try...Catch block and see whether you are getting exceptions. Whenever anybody talks about odd behavior in the Load event, it generally indicates one thing, and this just looks like another case: On certain setups (I think it may just be 64-bit OS), exceptions thrown in the Load event handler don't do anything other than exit the handler. You won't see the exception, the event handler will just exit abruptly. That kind of sounds like what you are seeing, so the Try...Catch block will tell you whether you are getting an exception.
    My usual boring signature: Nothing

  5. #5

    Thread Starter
    New Member
    Join Date
    Aug 2012
    Posts
    15

    Re: 2nd Form Load interupted by 1st forms calling event

    Thanks Shaggy,

    It is Win7 64bit. I will try that tomorrow and post my results!

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: 2nd Form Load interupted by 1st forms calling event

    That makes it virtually certain to be the case.

    The odd behavior of the Load Event is technically not a bug, but a disagreement between the OS and VS divisions of MS (OS & VS in MS), and seems likely to never be resolved. The manifestations can be totally perplexing, and it is a bit hard to say whether you are really seeing a case of this or not, so the easiest test is to put in the exception trap and see if you catch anything.
    My usual boring signature: Nothing

  7. #7
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: 2nd Form Load interupted by 1st forms calling event

    I have also saw this happen in a service on the 64 bit OS, took me a while to figure out what was going on. No errors were thrown and the service continued running but sometimes was not executing the entire code before exiting the sub. I went back and added a few try catch blocks and the problem went away. I also added code to log what and where the error was but the custom has never reported back on the issue. They just said the problem was solved and that was the end of it. I am still wondering what actually was happening there.

  8. #8

    Thread Starter
    New Member
    Join Date
    Aug 2012
    Posts
    15

    Re: 2nd Form Load interupted by 1st forms calling event

    That did it! The Try Catch revealed an attempt to parse a null into a string. Not sure why I didn't think of this as I have had to use Try Catch for this exact same situation before.....

    Thanks again guys!

  9. #9
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: 2nd Form Load interupted by 1st forms calling event

    That doesn't sound like a situation where Try...Catch is needed. Exception handling is slow, so if you can avoid it, do so (it's only slow if an exception is thrown, it isn't slow otherwise). If it is Null, check for that with IsDBNull rather than using the exception handling.
    My usual boring signature: Nothing

  10. #10

    Thread Starter
    New Member
    Join Date
    Aug 2012
    Posts
    15

    Re: 2nd Form Load interupted by 1st forms calling event

    I only put the try catch in there for troubleshooting purposes. I was using IsDBNull but like an idiot.

    Dim Val as string
    Val = result.items(0)
    If ISDBNull(Val) then Val = "1"
    Listbox9.Items.Add(Val)

    X.x assigned value to string before checking null lol counter
    productive. Fixed it though, thanks again

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width