469,917 Members | 1,829 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,917 developers. It's quick & easy.

VB.NET backcolor syntax

Hi,

Can anyone tell me the correct syntax when using a variable to control
the color property?

This works ok:
If ABC2flash Then Label61.BackColor = Color.Yellow

This doesn't, showing syntax error in source code:
Dim ABC1col As String = "Color.Yellow"
If ABC2flash Then Label61.BackColor = ABC1col

Thanks
Jul 21 '05 #1
4 17028
> Can anyone tell me the correct syntax when using a variable to control
the color property?

This works ok:
If ABC2flash Then Label61.BackColor = Color.Yellow

This doesn't, showing syntax error in source code:
Dim ABC1col As String = "Color.Yellow"
If ABC2flash Then Label61.BackColor = ABC1col


I don't use VB.NET myself (see the note at the end of this posting), but
I think I can guess at your problem. The BackColor property is a number
(in VB6 it would be a Long, but I'm not sure of the data type in VB.NET,
you'll have to look that up in your help files). You have defined
ABC1col as a String variable and are trying to assign a String variable
to a property requiring a numerical data type... hence, your error. Try
this (substituting the correct data type where I used <NumericDataType>
as a place holder):

Dim ABC1col As <NumericDataType> = Color.Yellow
If ABC2flash Then Label61.BackColor = ABC1col

Now, for the note I told you about...

Almost everybody in this newsgroup is using VB6 or lower. While you may
get a stray answer to VB.NET (including VB2003 and VB2005 which has
dropped .NET from its name) questions here, you should ask them in
newsgroups devoted exclusively to .NET programming. Look for newsgroups
with either the word "dotnet" or "vsnet" in their name.

For the microsoft news server, try these newsgroups for Visual Basic
..NET related questions...

microsoft.public.dotnet.languages.vb
microsoft.public.dotnet.languages.vb.upgrade
microsoft.public.dotnet.languages.vb.controls
microsoft.public.dotnet.languages.vb.data

And these for more general .NET questions

microsoft.public.dotnet.general
microsoft.public.vsnet.general

Note: There are many other .NET newgroups (use the first three "fields"
from the last two as templates when searching for them), but the above
ones should get you started.

Rick
Jul 21 '05 #2

<Da**@dimos.biz> wrote in message
news:a_********************@giganews.com...
Hi,

Can anyone tell me the correct syntax when using a variable to control
the color property?

This works ok:
If ABC2flash Then Label61.BackColor = Color.Yellow

This doesn't, showing syntax error in source code:
Dim ABC1col As String = "Color.Yellow"
If ABC2flash Then Label61.BackColor = ABC1col

Thanks


Use the Color.FromName function. You'll have to remove the "Color." part of
the string but it's a start.

Example:
Label.BackColor = Color.FromName("Yellow")

Keith R. Weimer
Way Too Happy Software
Jul 21 '05 #3
Many thanks Keith,

FromName works just fine !

Dave
Jul 22 '05 #4
Thanks Rick,

Tried your suggestion - it didn't work either, but thanks for the kind
suggestion.

The FromName option in other reply seems to work, so I'm sorted out ok.

Thanks for the advice on the correct groups.

Best regards

Dave
Jul 22 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by perspolis | last post: by
3 posts views Thread by WilsonSmith | last post: by
6 posts views Thread by LU | last post: by
reply views Thread by Jonesgj | last post: by
1 post views Thread by Nathan Sokalski | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.