Home » Category » Microsoft Visual Basic

Microsoft Visual Basic: Colors on Labels

200| Mon, 12 May 2008 14:21:00 GMT| scott_starker| Comments (9)
I'm doing a "character map" program that I want make one (or more)
characters change background and foreground colors. Each character has its
own Label. When I reach Label 46 it stops

Private Sub Label46_Click()
Label46.ForeColor = RGB(Label46.ForeColor Xor &HFF, &H0, &H0)
Label46.FontBold = Label46.FontBold Xor True
Label46.BackColor = Label46.BackColor Xor 1
End Sub

on the "Label46.ForeColor". The first 45 work! Is this a bug?

Scott

P.S. I have VB 6.

Keywords & Tags: colors, labels, microsoft, visual basic, vb

URL: http://www.programmerbase.com/visual-basic/80687/
 
«« Prev - Next »» 9 helpful answers below.
Scott Starker wrote:
> I'm doing a "character map" program that I want make one (or more)
> characters change background and foreground colors. Each character has its
> own Label. When I reach Label 46 it stops
> Private Sub Label46_Click()
> Label46.ForeColor = RGB(Label46.ForeColor Xor &HFF, &H0, &H0)
> Label46.FontBold = Label46.FontBold Xor True
> Label46.BackColor = Label46.BackColor Xor 1
> End Sub
> on the "Label46.ForeColor". The first 45 work! Is this a bug?


explain "stops"

bobo`bob | Mon, 12 May 2008 14:22:00 GMT |

"stop" means when I run the program I get a Run-time error '6': Overflow
message when I click on Label46.

"Bob O`Bob" <filterbob...yahoogroups.com> wrote in message
news:407D6BC2.79FF...yahoogroups.com...
> Scott Starker wrote:
its
>
> explain "stops"

scott_starker | Mon, 12 May 2008 14:23:00 GMT |

Scott Starker wrote:
> "stop" means when I run the program I get a Run-time error '6': Overflow
> message when I click on Label46.


... and you didn't think that, or the current value of .ForeColor,
were important enough to mention?

Bob

bobo`bob | Mon, 12 May 2008 14:24:00 GMT |

Scott-

Do yourself a favor and re-code that using a control array instead. Assuming
you're going to be using up to 255 labels to display all the fonts, you're
going to run into difficulties because of the limitation of controls allowed
on a form. On top of that, it will cut down your code considerably as well.

HTH

Matt

"Scott Starker" <Scott_Starker...sil.org> wrote in message
news:O1GG6AkIEHA.3528...TK2MSFTNGP09.phx.gbl...
> I'm doing a "character map" program that I want make one (or more)
> characters change background and foreground colors. Each character has its
> own Label. When I reach Label 46 it stops
> Private Sub Label46_Click()
> Label46.ForeColor = RGB(Label46.ForeColor Xor &HFF, &H0, &H0)
> Label46.FontBold = Label46.FontBold Xor True
> Label46.BackColor = Label46.BackColor Xor 1
> End Sub
> on the "Label46.ForeColor". The first 45 work! Is this a bug?
> Scott
> P.S. I have VB 6.
>

matt_williamson | Mon, 12 May 2008 14:25:00 GMT |

Bob O'Bob,

I wanted to say "Shame on you." because I "know" that I checked all of the
.ForeColor's. But "Shame on me." because the .ForeColor's were &H80000000
instead of &H00000000! So, I've my problem is solved...

"Bob O`Bob" <filterbob...yahoogroups.com> wrote in message
news:407D782F.4ED8...yahoogroups.com...
> Scott Starker wrote:
>
> ... and you didn't think that, or the current value of .ForeColor,
> were important enough to mention?
>
> Bob

scott_starker | Mon, 12 May 2008 14:26:00 GMT |

Matt,

I didn't know if I could .ForeColor, .FontBold and .BackColor with a control
array but now I do. Thanks a lot.

Scott

"Matt Williamson" <ih8spam...spamsux.org> wrote in message
news:%23KYbojkIEHA.3664...TK2MSFTNGP11.phx.gbl...
> Scott-
> Do yourself a favor and re-code that using a control array instead.

Assuming
> you're going to be using up to 255 labels to display all the fonts, you're
> going to run into difficulties because of the limitation of controls

allowed
> on a form. On top of that, it will cut down your code considerably as

well.
> HTH
> Matt
> "Scott Starker" <Scott_Starker...sil.org> wrote in message
> news:O1GG6AkIEHA.3528...TK2MSFTNGP09.phx.gbl...
its
>

scott_starker | Mon, 12 May 2008 14:27:00 GMT |

Scott Starker wrote:

> I didn't know if I could .ForeColor, .FontBold and .BackColor with a contr
ol
> array but now I do. Thanks a lot.


maybe something like this...

Private Sub LabelArray_Click(Index as integer)
With LabelArray(Index)
.ForeColor = RGB((.ForeColor And vbWhite) Xor &HFF, &H0, &H0)
.FontBold = Not .FontBold
.BackColor = .BackColor Xor 1
End With
End Sub

Note also the "And" clause I've added, which might give wierd results
if it encounters a system color, but should prevent a crash.

And while "Xor True" hardly differs from "Not", I believe the latter
is significantly more clearly stated.

I'm guessing .Backcolor is a system color you're swapping with the
adjacent one? Seems inconsistent with the explicit colors setting
in .Forecolor, but if that's what you want...

Bob
--

bobo`bob | Mon, 12 May 2008 14:28:00 GMT |

>you're going to run into difficulties because of the limitation of controls
allowed on a form<

Ummmm.....Ok...

What <is> the limitation of # of controls on a form?

Pete :-)

pete | Mon, 12 May 2008 14:29:00 GMT |

255 i believe

"Pete" <psch_delete...delete_NOSPAMimt.net> wrote in message
news:uoTe0QnIEHA.2924...TK2MSFTNGP09.phx.gbl...
> allowed on a form<
> Ummmm.....Ok...
> What <is> the limitation of # of controls on a form?
> Pete :-)
>

rickmogstad | Mon, 12 May 2008 14:30:00 GMT |

Microsoft Visual Basic Hot Answers

Microsoft Visual Basic New questions

Microsoft Visual Basic Related Categories