Export (0) Print
Expand All
Expand Minimize

Unload method cannot be upgraded

Visual Studio .NET 2003

In cases where an object is late bound, the Unload method cannot be upgraded. For example, the following Visual Basic 6.0 code will cause a compilation error after upgrading to Visual Basic .NET.

' Visual Basic 6.0
Dim o As Object
Private Sub Command1_Click()
    Set o = New Form1
    o.Show
End Sub

Private Sub Command2_Click()
    Unload o
End Sub
' After upgrade to Visual Basic .NET
Dim o As Object
Private Sub Command1_Click(ByVal EventSender As System.Object, ByVal EventArgs As System.EventArgs) Handles Command1.Click
    o = New Form1
    o.Show()
End Sub

Private Sub Command2_Click(ByVal EventSender As System.Object, ByVal EventArgs As System.EventArgs) Handles Command2.Click
    ' UPGRADE_ISSUE: Unload o was not upgraded.
    Unload o
End Sub

What to do next

  • Modify the code to be early bound to Form1 instead of Object, and call the Close method instead of Unload.
    ' Modified Visual Basic .NET code
    Dim o As Form1
    Private Sub Command1_Click(ByVal EventSender As System.Object, ByVal EventArgs As System.EventArgs) Handles Command1.Click
        o = New Form1
        o.Show()
    End Sub
    
    Private Sub Command2_Click(ByVal EventSender As System.Object, ByVal EventArgs As System.EventArgs) Handles Command2.Click
        o.Close()
    End Sub
    

See Also

Form Object Changes in Visual Basic .NET | Control Changes in Visual Basic .NET

Show:
© 2015 Microsoft