Constant Expression Is Required Vb.Net 2008

R

Rob Blackmore

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
 
C

Cor Ligthert[MVP]

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
 
R

Rob Blackmore

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

Cor Ligthert[MVP]

You mean that your attribute is a constant?

Cor

Rob Blackmore said:
Not for attribute classes as you always set the value via the constructor?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top