Main Page | Report Page

 

  .NET DotNet Forum Index » VB.NET Forum (Visual Basic .NET) » qualifying expression will not be evaluated

Author Message
Ben
Posted: Fri Jun 22, 2007 12:22 pm
 
Hi,

i would like to have an explanation about this:
This works, but i get the message in code-behind:
access of shared member,... or nested type through an instance; qualifying
expression will not be evaluated.

Dim cl As System.Drawing.Color
Label1.ForeColor = cl.FromName(DropDownList1.SelectedValue)

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack=true>
<asp:ListItem Text="red" Value="red"></asp:ListItem>

By the way, i know that there is another solution:
System.Drawing.Color.Fromname(DropDownList1.SelectedValue).

Thanks
Ben
 
rowe_newsgroups
Posted: Fri Jun 22, 2007 12:27 pm
 
On Jun 22, 1:22 pm, "Ben" <b@bn> wrote:
Quote:
Hi,

i would like to have an explanation about this:
This works, but i get the message in code-behind:
access of shared member,... or nested type through an instance; qualifying
expression will not be evaluated.

Dim cl As System.Drawing.Color
Label1.ForeColor = cl.FromName(DropDownList1.SelectedValue)

asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack=true
asp:ListItem Text="red" Value="red"></asp:ListItem

By the way, i know that there is another solution:
System.Drawing.Color.Fromname(DropDownList1.SelectedValue).

Thanks
Ben


Quote:
By the way, i know that there is another solution:
System.Drawing.Color.Fromname(DropDownList1.SelectedValue).

Won't using that take away the error?

Thanks,

Seth Rowe
 
Ben
Posted: Fri Jun 22, 2007 2:15 pm
 
I would like an explanation about the fact i get that error and nevertheless
it works. What does that error mean?
i mentioned that there is a solution without error in order to avoid that i
get that solution as answer on my post.


"rowe_newsgroups" <rowe_email@yahoo.com> schreef in bericht
news:1182533270.737785.313380@n60g2000hse.googlegroups.com...
Quote:
On Jun 22, 1:22 pm, "Ben" <b@bn> wrote:
Hi,

i would like to have an explanation about this:
This works, but i get the message in code-behind:
access of shared member,... or nested type through an instance;
qualifying
expression will not be evaluated.

Dim cl As System.Drawing.Color
Label1.ForeColor = cl.FromName(DropDownList1.SelectedValue)

asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack=true
asp:ListItem Text="red" Value="red"></asp:ListItem

By the way, i know that there is another solution:
System.Drawing.Color.Fromname(DropDownList1.SelectedValue).

Thanks
Ben


By the way, i know that there is another solution:
System.Drawing.Color.Fromname(DropDownList1.SelectedValue).

Won't using that take away the error?

Thanks,

Seth Rowe

 
Herfried K. Wagner [MVP]
Posted: Fri Jun 22, 2007 7:02 pm
 
"Ben" <b@bn> schrieb:
Quote:
I would like an explanation about the fact i get that error and
nevertheless it works. What does that error mean?
i mentioned that there is a solution without error in order to avoid that
i get that solution as answer on my post.

'FromName' is a shared member of 'Color'. Thus it's not necessary to call
it on an instance. It can be called on the type directly ('... =
Color.FromName(...)'). The compile-time error does not make much sense in
your simple scenario, but it would if you replace the part on the left hand
side of the '.' by a function call, for example ('... =
GetColor().FromName(...)'). In this case, 'GetColor' won't get called
because the compiler will only emit a call to 'Color.FromName'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
 
rowe_newsgroups
Posted: Fri Jun 22, 2007 7:09 pm
 
On Jun 22, 3:15 pm, "Ben" <b@bn> wrote:
Quote:
I would like an explanation about the fact i get that error and nevertheless
it works. What does that error mean?
i mentioned that there is a solution without error in order to avoid that i
get that solution as answer on my post.

"rowe_newsgroups" <rowe_em...@yahoo.com> schreef in berichtnews:1182533270.737785.313380@n60g2000hse.googlegroups.com...

On Jun 22, 1:22 pm, "Ben" <b@bn> wrote:
Hi,

i would like to have an explanation about this:
This works, but i get the message in code-behind:
access of shared member,... or nested type through an instance;
qualifying
expression will not be evaluated.

Dim cl As System.Drawing.Color
Label1.ForeColor = cl.FromName(DropDownList1.SelectedValue)

asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack=true
asp:ListItem Text="red" Value="red"></asp:ListItem

By the way, i know that there is another solution:
System.Drawing.Color.Fromname(DropDownList1.SelectedValue).

Thanks
Ben

By the way, i know that there is another solution:
System.Drawing.Color.Fromname(DropDownList1.SelectedValue).

Won't using that take away the error?

Thanks,

Seth Rowe

It's fairly simple - In your code cl is an instance of the color
class. FromName is a shared method of the Color class which means that
cl also has the method. Since shared methods can't be used with
instance the compiler will just ignore the instance (cl) and go
directly to the class (System.Drawing.Color). This means the "will not
be evaluated" error is talking about the instance and not the method -
that's why the expression still works. As for why the warning is even
generated I'm not sure - perhaps to prevent someone from making a
pointless variable when they should just call the method directly (you
know, like you did in your code Smile )

Thanks,

Seth Rowe
 
Ben
Posted: Sat Jun 23, 2007 4:07 am
 
That are what i call good explanations and to the point.
Thanks to both

"rowe_newsgroups" <rowe_email@yahoo.com> schreef in bericht
news:1182557396.848598.213710@m37g2000prh.googlegroups.com...
Quote:
On Jun 22, 3:15 pm, "Ben" <b@bn> wrote:
I would like an explanation about the fact i get that error and
nevertheless
it works. What does that error mean?
i mentioned that there is a solution without error in order to avoid that
i
get that solution as answer on my post.

"rowe_newsgroups" <rowe_em...@yahoo.com> schreef in
berichtnews:1182533270.737785.313380@n60g2000hse.googlegroups.com...

On Jun 22, 1:22 pm, "Ben" <b@bn> wrote:
Hi,

i would like to have an explanation about this:
This works, but i get the message in code-behind:
access of shared member,... or nested type through an instance;
qualifying
expression will not be evaluated.

Dim cl As System.Drawing.Color
Label1.ForeColor = cl.FromName(DropDownList1.SelectedValue)

asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack=true
asp:ListItem Text="red" Value="red"></asp:ListItem

By the way, i know that there is another solution:
System.Drawing.Color.Fromname(DropDownList1.SelectedValue).

Thanks
Ben

By the way, i know that there is another solution:
System.Drawing.Color.Fromname(DropDownList1.SelectedValue).

Won't using that take away the error?

Thanks,

Seth Rowe

It's fairly simple - In your code cl is an instance of the color
class. FromName is a shared method of the Color class which means that
cl also has the method. Since shared methods can't be used with
instance the compiler will just ignore the instance (cl) and go
directly to the class (System.Drawing.Color). This means the "will not
be evaluated" error is talking about the instance and not the method -
that's why the expression still works. As for why the warning is even
generated I'm not sure - perhaps to prevent someone from making a
pointless variable when they should just call the method directly (you
know, like you did in your code Smile )

Thanks,

Seth Rowe

 
 
Page 1 of 1    
All times are GMT - 5 Hours
The time now is Thu May 05, 2016 3:39 am