Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleUse the Obsolete attribute in VB .NET
DescriptionThis example shows how to use the Obsolete attribute in VB .NET.
KeywordsObsolete, attribute, VB.NET, property
CategoriesVB.NET
 
(One of my favorites.) The Obsolete attribute tells the Visual Basic IDE that a method is obsolete. You can indicate a string to display to the developer (usually telling what newer method to use instead) and you can determine whether the IDE treats using this method as a warning or an error.

In this example, the ObsoleteAllowed method is marked as obsolete but is allowed. The IDE flags the line calling the method and displays a warning in the Tasks pane.

The ObsoleteDisAllowed method is marked as obsolete and the final parameter to the attribute indicates that its use is not allowed. The IDE flags the line calling the method, displays an error message in the Tasks pane, and will not allow the program to run if this method is in use.

 
Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
    e As System.EventArgs) Handles MyBase.Load
    ObsoleteAllowed()
    ObsoleteDisAllowed()
End Sub

<Obsolete("Don't use this routine any more. Use the new one " & _
    "instead.")> _
Private Sub ObsoleteAllowed()

End Sub

<Obsolete("You MUST not use this routine any more. Use the " & _
    "new one instead.", True)> _
Private Sub ObsoleteDisAllowed()

End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated