Link to home
Start Free TrialLog in
Avatar of bearpaws
bearpaws

asked on

Exception error

Hi Folks,

    I am having alot of problems with this program. I have a splash screen, which the user clicks on the image and then it shows another form, the main menu form. From the main menu form, they have alot of options. One menu option is a search form.
So, we have the splash form hidden, the main menu form showing (and that is okay)
but on the search form I have a button  that allows them go to a form to select one of two options, which goes to another form.
 What happens is this, and it is driving me absolutely mad)


"An unhandled exception of type 'System.ObjectDisposedException' occurred in system.windows.forms.dll
Additional information: Cannot access a disposed object named "Button"."

Or I recieve the same message for "Listbox"

it then shows the splash form in the debugger etc. I have tried to trace it and step thru the code, but it takes back to the coding of the splash form.

I have no clue what is going on and how to cure it..
I was alwasy taught to create the form you want, show it and then close the previous form (or the form that called the new one)
But when I use Me.close, it seems to cause the problem too.

I have deleted the buttons on the form that seems to cause the application to crash and redid them etc. That didn't work. Should I get rid of the "Inherits System.Windows.Forms.Form"

This is the coding in the splash form. I would like to close the form and forms that I don't use, but it seems when I use the Me.close, it causes crashes..

    Private Sub Splash_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Splash.Click
        Dim frmMainMenu As New frmMainMenu
        frmMainMenu.WindowState = FormWindowState.Maximized
        frmMainMenu.Show()  
       ' Me.Close()
        Me.Visible = False
        frmMainMenu.Focus()

    End Sub
I wonder about if I have a corruption or something??
I just know there is something I am not getting here and I don't know what it is either...
any help appreciated...


Avatar of bman9111
bman9111

I would first put try catch around ur codes in each form

when I have a splash screen I make my startup form be sub main and then create a module and have something like this;


    Public Sub main()
       Dim frmmdiparent As New FrmMdiParent
'shows the splash screen
       Dim frmsplash As New frmsplash
        frmsplash.Show()
       
   
        Application.DoEvents()
        'run application
'hides splash screen and then runs the main mdiparent form
        frmsplash.Hide()
        Application.Run(frmmdiparent)
ASKER CERTIFIED SOLUTION
Avatar of Ravi Singh
Ravi Singh
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bearpaws

ASKER

I had forgotten about the fact that one needs to create an application entry point using
Sub Main! That cleaned a great deal up for me. But my splash screens zips on by - what do I need to do so the splash screen shows?? I added a timer, 360, you would hardly knows it there...
The other thing I discovered, and this is going to be hard for me to explain, is that on some of the forms , after I dim as new etc, I often have a *value* to pass to the new form. So, you are right, it blows if I use close and okay if I use hide. My concern is what happens to all these *hidden* forms?? Keeping track of what hidden is just not feasable. I would have thought if I set a variable to a value and then pass the variable, it would be okay, but apparently not and this confuses me.
Here is an example of what I mean:

This is forma, which calls a second form, either frmBrowseContacts or frmBrowseAllContacts. I am actually passing the *pk* from a listbox. If I use Me.close, it will after about 3 clicks, throw an exception. If I use *me.hide*, it is okay. I find this confusing... I think the exception that was being thrown as to the listbox or button,came from this form. I also have a button event that passes the *pk* to the next form.

Private Sub lstContacts_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstContact.Click
        Dim vrecid As String = lstContact.SelectedValue()

        If lblSelType.Text = "B" Then
            Dim frmBrowseContacts As New frmBrowseContacts
            frmBrowseContacts.lblContactId.Text = vrecid
            frmBrowseContacts.WindowState = FormWindowState.Normal
            frmBrowseContacts.Show()
            Me.Visible = False
            'Me.Close()
            Me.Hide()
            frmBrowseContacts.Focus()
        Else
            Dim frmChangeContacts As New frmChangeContacts
            frmChangeContacts.lblContactId.Text = vrecid
            frmChangeContacts.WindowState = FormWindowState.Normal
            frmChangeContacts.Show()
            Me.Visible = False
            ' Me.Close()
            Me.Hide()
            frmChangeContacts.Focus()

        End If