The discarded object cannot be accessed. Object name: 'Form3' (VS)

25 Views Asked by At

I have a form that has a button that opens another form, the latter opens another form automatically; the last form has a button that closes the last 2 forms and opens the first one. When I run it, in the last button mentioned, I get an error with the message that is in the title.

-Here I leave a link where you can download the program: poe_promGA The program is made in visual basic 2010.

  • Here I leave the code (I will only show the code of the button that leads to the other forms).
Private Sub btncalcular_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncalcular.Click
         If r1.Checked Then
             v = v + 1
             r1.BackColor = Color.Green
         ElseIf RadioButton1.Checked Then
             RadioButton1.BackColor = Color.Red
         ElseIf RadioButton2.Checked Then
             RadioButton2.BackColor = Color.Red
         Else
             PictureBox11.Image = My.Resources._126546204_gettyimages_11939515471
         End If

         If r2.Checked Then
             v = v + 1
             r2.BackColor = Color.Green
         ElseIf RadioButton1.Checked Then
             RadioButton3.BackColor = Color.Red
         ElseIf RadioButton4.Checked Then
             RadioButton4.BackColor = Color.Red
         Else
             PictureBox12.Image = My.Resources._126546204_gettyimages_11939515471
         End If

         If TextBox1.Text = "6.403" Or TextBox1.Text = "6.40" Or TextBox1.Text = "6.4" Then
             v = v + 1
             TextBox1.BackColor = Color.Green
         Else
             TextBox1.BackColor = Color.Red
         End If

         If TextBox2.Text = "15.297" Or TextBox2.Text = "15.29" Or TextBox2.Text = "15.2" Then
             v = v + 1
             TextBox2.BackColor = Color.Green
         Else
             TextBox2.BackColor = Color.Red
         End If

         If TextBox3.Text = "10.630" Or TextBox3.Text = "10.63" Or TextBox3.Text = "10.6" Then
             v = v + 1
             TextBox3.BackColor = Color.Green
         Else
             TextBox3.BackColor = Color.Red
         End If

         'End
         cont = cont + 1

         If cont = 1 Then
             btncalculate.Enabled = False
         Else
             btncalculate.Enabled = False
         End If

         'Average
         Module1.vr = v
         m = (10 * v) / 5
         Module1.rs = m
         Me.Dispose()
         Form3.Show()
     End Sub
Public Class Form3

     Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
         Me.WindowState = FormWindowState.Maximized
         Dim form4 As New Form4
         form4.StartPosition = FormStartPosition.Manual
         form4.Location = New Point(Me.Location.X + (Me.Width - form4.Width) / 2, Me.Location.Y + (Me.Height - form4.Height) / 2)
         form4.ShowDialog()
     End Sub
End Class
Private Sub btnvolver_try_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnvolver_try.Click
         Form3.Dispose()
         Form2.Show()
     End Sub

     Private Sub btnregresar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnregresar.Click
         Form3.Dispose()
         Form1.Show()
     End Sub

Try changing the order of the code; I also tried changing "close" to "dispose", although I think it has to do with the fact that form3 opens a form automatically.

0

There are 0 best solutions below