conquistador
conquistador

Reputation: 693

How to use System.IDisposable.Dispose?

Im getting a warning in my object which transfers value from one form to another The warning said Button1 must call System.IDisposable.Dispose on Object Form1 before references to it are of scope

This is my code on my button1:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim Form1 As New Form1
    Form1.a1 = TextBox1.Text
    Form1.a2 = TextBox2.Text
    Form1.a3 = TextBox3.Text
    Form1.a4 = TextBox4.Text
    Form1.a5 = TextBox5.Text
    Form1.a6 = TextBox6.Text
    Form1.a7 = TextBox7.Text
    Form1.a8 = TextBox8.Text
    Form1.a9 = TextBox9.Text
    Form1.a10 = TextBox10.Text
    Form1.Show()
    Form1.SetPrice()
    Me.Close()
End Sub

How to use System.IDisposable.Dispose?

Upvotes: 1

Views: 643

Answers (1)

mr_plum
mr_plum

Reputation: 2437

It sounds like the listed code is not in Form1. Whatever form it's in is instantiating a Form1, but not disposing it. Just wrap Form1 in a Using statement:

Using Form1 As New Form1
    Form1.a1 = TextBox1.Text
    Form1.a2 = TextBox2.Text
    Form1.a3 = TextBox3.Text
    Form1.a4 = TextBox4.Text
    Form1.a5 = TextBox5.Text
    Form1.a6 = TextBox6.Text
    Form1.a7 = TextBox7.Text
    Form1.a8 = TextBox8.Text
    Form1.a9 = TextBox9.Text
    Form1.a10 = TextBox10.Text
    Form1.Show()
    Form1.SetPrice()
End Using
Me.Close()

Upvotes: 1

Related Questions