Click here to Skip to main content
       

Visual Basic

 
AnswerRe: Use Stored Procedure with VB6 ADODC PinmvpEddy Vluggen5-Feb-13 3:17 
AnswerRe: Use Stored Procedure with VB6 ADODC PinmemberRichard Deeming5-Feb-13 1:31 
GeneralRe: Use Stored Procedure with VB6 ADODC PinmemberCHill606-Feb-13 3:52 
GeneralRe: Use Stored Procedure with VB6 ADODC PinmvpDave Kreskowiak6-Feb-13 5:43 
AnswerRe: Use Stored Procedure with VB6 ADODC PinmemberYusuf Mohammad5-Feb-13 2:05 
QuestionIN Visual Studio 2010 Pinmemberhtet htet soe4-Feb-13 22:44 
AnswerRe: IN Visual Studio 2010 PinmemberSimon_Whale4-Feb-13 23:17 
Questionpng lossless resize PinmemberJellyCoe4-Feb-13 5:39 
AnswerRe: png lossless resize PinmemberRene Pilon4-Feb-13 6:54 
QuestionCustom Tab Control that I found on here PinmemberNSoft Studios3-Feb-13 13:10 
AnswerRe: Custom Tab Control that I found on here PinmvpDave Kreskowiak3-Feb-13 13:19 
GeneralRe: Custom Tab Control that I found on here PinmemberNSoft Studios3-Feb-13 13:44 
GeneralRe: Custom Tab Control that I found on here PinmvpRichard MacCutchan3-Feb-13 22:40 
QuestionRetrieving Custom Attributes PinmemberDisIsHoody1-Feb-13 21:34 
I'm writing an update to a software package that takes binary data from an instrument and creates a spreadsheet. There is a column that list a reading mode that in the older version of the software outputted either "TC" or "QM". Now in the updated version I want it to write something more descriptive; that being either "Time Corrected" or "Quick Mode", but I still want to maintain backwards compatibility.
 
I thought the best way to do this would be to use custom attributes where the new description and old description would be saved and then based on the settings of the software the program could choose the proper description.
 
First I created a custom attribute class:
<AttributeUsage(AttributeTargets.Field, AllowMultiple:=True, Inherited:=False)>
Public Class OutputDescriptionAttribute
    Inherits Attribute
 
    Private _oldDescription As String
    Private _newDescription As String
 
    Public Sub New(oldDescription As String, newDescription As String)
        Me._oldDescription = oldDescription
        Me._newDescription = newDescription
    End Sub
End Class
 
Then I created the enum and applied the attributes:
Public Enum ReadingModeType
    <OutputDescription("TC", "TimeCorrected")> TimeCorrected
    <OutputDescription("QM", "QuickMode")> QuickMode
End Enum
 
Lastly I copied a method off of Microsoft's website that is supposed to get the values from custom attributes:
 Public Shared Sub GetDescription(t As Type)
        ' Get instance of the attribute. 
        Dim MyAttribute As OutputDescriptionAttribute =
            CType(Attribute.GetCustomAttribute(t, GetType(OutputDescriptionAttribute)), OutputDescriptionAttribute)
 
        If MyAttribute Is Nothing Then
            Console.WriteLine("The attribute was not found.")
        Else
            ' Get the Name value.
            'Console.WriteLine("The Name Attribute is: {0}.", MyAttribute.Name)
            '' Get the Level value.
            'Console.WriteLine("The Level Attribute is: {0}.", MyAttribute.Level)
            '' Get the Reviewed value.
            'Console.WriteLine("The Reviewed Attribute is: {0}.", MyAttribute.Reviewed)
        End If
    End Sub
 
I got this method from http://msdn.microsoft.com/en-us/library/71s1zwct.aspx[^]. I then called this method like so:
 Private Sub MainWindow_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
        Dim s As ReadingModeType = ReadingModeType.QuickMode
        test.GetDescription(s.GetType)
    End Sub
 
However when I step through the code in the GetDescription method, the MyAttribute object returns nothing. This is my first time working with custom attributes so I know I'm probably missing something very simple. Can anyone please advise me how I can retrieve the descriptions for the attribute applied to the specified enum value?
 
Thanks in advance.
AnswerRe: Retrieving Custom Attributes PinmvpEddy Vluggen2-Feb-13 2:11 
QuestionSearch criteria - classic asp not working Pinmembermiss78631-Jan-13 4:01 
AnswerRe: Search criteria - classic asp not working PinmvpEddy Vluggen31-Jan-13 10:18 
GeneralRe: Search criteria - classic asp not working Pinmembermiss7866-Feb-13 1:03 
GeneralRe: Search criteria - classic asp not working PinmvpEddy Vluggen6-Feb-13 7:11 
GeneralRe: Search criteria - classic asp not working Pinmembermiss7866-Feb-13 23:26 
GeneralRe: Search criteria - classic asp not working PinmvpEddy Vluggen7-Feb-13 8:13 
AnswerRe: Search criteria - classic asp not working PinmvpEddy Vluggen8-Feb-13 11:04 
QuestionWebBrowser Dock covers up statusstrip PinmemberNSoft Studios30-Jan-13 15:46 
AnswerRe: WebBrowser Dock covers up statusstrip PinmvpRichard MacCutchan30-Jan-13 22:13 
AnswerRe: WebBrowser Dock covers up statusstrip PinmvpEddy Vluggen30-Jan-13 22:36 
GeneralRe: WebBrowser Dock covers up statusstrip PinmvpDave Kreskowiak31-Jan-13 3:35 
SuggestionRe: WebBrowser Dock covers up statusstrip PinmvpEddy Vluggen31-Jan-13 3:38 
GeneralRe: WebBrowser Dock covers up statusstrip PinmvpDave Kreskowiak31-Jan-13 6:52 
GeneralRe: WebBrowser Dock covers up statusstrip PinmvpEddy Vluggen31-Jan-13 10:12 
GeneralRe: WebBrowser Dock covers up statusstrip PinmemberNSoft Studios3-Feb-13 12:58 
AnswerRe: WebBrowser Dock covers up statusstrip Pinmemberrohitvermasrt31-Jan-13 18:28 
QuestionQuery dataTable with .Compute Pinmembermebjen30-Jan-13 9:05 
AnswerRe: Query dataTable with .Compute PinmvpDave Kreskowiak30-Jan-13 10:20 
GeneralRe: Query dataTable with .Compute Pinmembermebjen30-Jan-13 10:45 
GeneralRe: Query dataTable with .Compute PinmvpDave Kreskowiak30-Jan-13 14:28 
QuestionWindows admin mode mistries Pinmembersolankinkdpr30-Jan-13 1:11 
AnswerRe: Windows admin mode mistries PinmvpEddy Vluggen30-Jan-13 7:51 
GeneralRe: Windows admin mode mistries Pinmembersolankinkdpr30-Jan-13 19:07 
AnswerRe: Windows admin mode mistries PinmvpEddy Vluggen30-Jan-13 22:35 
GeneralRe: Windows admin mode mistries Pinmembersolankinkdpr31-Jan-13 2:29 
GeneralRe: Windows admin mode mistries PinmvpEddy Vluggen31-Jan-13 3:21 
AnswerRe: Windows admin mode mistries PinmvpDave Kreskowiak30-Jan-13 8:26 
Questionserial number with project Pinmemberolivertechy29-Jan-13 15:33 
AnswerRe: serial number with project PinmvpEddy Vluggen30-Jan-13 8:17 
QuestionParse XML Response String And Get Usable Variables Pinmemberpjgoodis29-Jan-13 4:46 
AnswerRe: Parse XML Response String And Get Usable Variables PinmemberAlan N29-Jan-13 6:05 
GeneralRe: Parse XML Response String And Get Usable Variables Pinmemberpjgoodis29-Jan-13 22:05 
GeneralRe: Parse XML Response String And Get Usable Variables [modified] PingroupStyleTech Solutions Ltd4-Feb-13 6:28 
QuestionMicrosoft ReportViewer PinmemberIgaBaro28-Jan-13 16:30 
AnswerRe: Microsoft ReportViewer PinmemberIgaBaro29-Jan-13 15:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web02 | 2.8.140905.1 | Last Updated 16 Sep 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid