I am trying to create an attribute of type Icon and have the following code:

<AttributeUsage(AttributeTargets.Class)> _
Public Class PIMSGridViewIconAttribute

Inherits System.Attribute

'/// Private variables
Private oPiGridViewIcon As System.Drawing.Icon = Nothing

'/// Construtor
Public Sub New(ByVal Value As System.Drawing.Icon)
oPiGridViewIcon = Value
End Sub

'/// Public properties
Public ReadOnly Property GridViewIcon() As System.Drawing.Icon
Get
Return oPiGridViewIcon
End Get
End Property

End Class


And then on a class I attempt to set it to an icon within a resource file
with:

<PIMSGridViewIcon(My.Resources.resIcons.Team)> _


However, this gives an error of "Constant expression is required.". Please
can someone advise what I am doing wrong and how I can set the attributes
value per class?

Kind regards

Rob

Re: Constant Expression Is Required Vb.Net 2008 by Cor

Cor
Wed May 07 22:37:20 CDT 2008

Rob,

To Set a Property you need at least a Set
(

Set
oPiGridViewIcon = Value 'this is not the value from your constructor
but a key word
End Set

I would not use the keyword Value in the constructor as a reference

Cor

"Rob Blackmore" <rob@robblackmore.com> schreef in bericht
news:87DBE825-1BDF-4699-B512-43882D4DD60A@microsoft.com...
>I am trying to create an attribute of type Icon and have the following
>code:
>
> <AttributeUsage(AttributeTargets.Class)> _
> Public Class PIMSGridViewIconAttribute
>
> Inherits System.Attribute
>
> '/// Private variables
> Private oPiGridViewIcon As System.Drawing.Icon = Nothing
>
> '/// Construtor
> Public Sub New(ByVal Value As System.Drawing.Icon)
> oPiGridViewIcon = Value
> End Sub
>
> '/// Public properties
> Public ReadOnly Property GridViewIcon() As System.Drawing.Icon
> Get
> Return oPiGridViewIcon
> End Get
> End Property
>
> End Class
>
>
> And then on a class I attempt to set it to an icon within a resource file
> with:
>
> <PIMSGridViewIcon(My.Resources.resIcons.Team)> _
>
>
> However, this gives an error of "Constant expression is required.".
> Please can someone advise what I am doing wrong and how I can set the
> attributes value per class?
>
> Kind regards
>
> Rob
>


Re: Constant Expression Is Required Vb.Net 2008 by Rob

Rob
Thu May 08 01:39:38 CDT 2008

Not for attribute classes as you always set the value via the constructor?


"Cor Ligthert[MVP]" <notmyfirstname@planet.nl> wrote in message
news:B31A0E71-23EA-4025-822B-818E4F655C91@microsoft.com...
> Rob,
>
> To Set a Property you need at least a Set
> (
>
> Set
> oPiGridViewIcon = Value 'this is not the value from your constructor
> but a key word
> End Set
>
> I would not use the keyword Value in the constructor as a reference
>
> Cor
>
> "Rob Blackmore" <rob@robblackmore.com> schreef in bericht
> news:87DBE825-1BDF-4699-B512-43882D4DD60A@microsoft.com...
>>I am trying to create an attribute of type Icon and have the following
>>code:
>>
>> <AttributeUsage(AttributeTargets.Class)> _
>> Public Class PIMSGridViewIconAttribute
>>
>> Inherits System.Attribute
>>
>> '/// Private variables
>> Private oPiGridViewIcon As System.Drawing.Icon = Nothing
>>
>> '/// Construtor
>> Public Sub New(ByVal Value As System.Drawing.Icon)
>> oPiGridViewIcon = Value
>> End Sub
>>
>> '/// Public properties
>> Public ReadOnly Property GridViewIcon() As System.Drawing.Icon
>> Get
>> Return oPiGridViewIcon
>> End Get
>> End Property
>>
>> End Class
>>
>>
>> And then on a class I attempt to set it to an icon within a resource file
>> with:
>>
>> <PIMSGridViewIcon(My.Resources.resIcons.Team)> _
>>
>>
>> However, this gives an error of "Constant expression is required.".
>> Please can someone advise what I am doing wrong and how I can set the
>> attributes value per class?
>>
>> Kind regards
>>
>> Rob
>>
>


Re: Constant Expression Is Required Vb.Net 2008 by Cor

Cor
Thu May 08 05:23:51 CDT 2008

You mean that your attribute is a constant?

Cor

"Rob Blackmore" <rob@robblackmore.com> schreef in bericht
news:474DA269-C21D-4EB1-9390-7D220F4AF677@microsoft.com...
> Not for attribute classes as you always set the value via the constructor?
>
>
> "Cor Ligthert[MVP]" <notmyfirstname@planet.nl> wrote in message
> news:B31A0E71-23EA-4025-822B-818E4F655C91@microsoft.com...
>> Rob,
>>
>> To Set a Property you need at least a Set
>> (
>>
>> Set
>> oPiGridViewIcon = Value 'this is not the value from your constructor
>> but a key word
>> End Set
>>
>> I would not use the keyword Value in the constructor as a reference
>>
>> Cor
>>
>> "Rob Blackmore" <rob@robblackmore.com> schreef in bericht
>> news:87DBE825-1BDF-4699-B512-43882D4DD60A@microsoft.com...
>>>I am trying to create an attribute of type Icon and have the following
>>>code:
>>>
>>> <AttributeUsage(AttributeTargets.Class)> _
>>> Public Class PIMSGridViewIconAttribute
>>>
>>> Inherits System.Attribute
>>>
>>> '/// Private variables
>>> Private oPiGridViewIcon As System.Drawing.Icon = Nothing
>>>
>>> '/// Construtor
>>> Public Sub New(ByVal Value As System.Drawing.Icon)
>>> oPiGridViewIcon = Value
>>> End Sub
>>>
>>> '/// Public properties
>>> Public ReadOnly Property GridViewIcon() As System.Drawing.Icon
>>> Get
>>> Return oPiGridViewIcon
>>> End Get
>>> End Property
>>>
>>> End Class
>>>
>>>
>>> And then on a class I attempt to set it to an icon within a resource
>>> file with:
>>>
>>> <PIMSGridViewIcon(My.Resources.resIcons.Team)> _
>>>
>>>
>>> However, this gives an error of "Constant expression is required.".
>>> Please can someone advise what I am doing wrong and how I can set the
>>> attributes value per class?
>>>
>>> Kind regards
>>>
>>> Rob
>>>
>>
>