By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,805 Members | 1,202 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,805 IT Pros & Developers. It's quick & easy.

prob with array of colors from vb6 to vb.net

P: n/a
B
Hello,

I am trying to migrate a vb6 app to vb.net. In one piece
of the vb6 app I have a label where the label backcolor
changes every 5 seconds on a timer. So I created an array
of colors as follows and then run the array in the timer
event in vb6. Not working in vb.net. How would I do this
in vb.net?

vb6 code:
-----------------------------------------
Const ORANGISH As Long = &HC0C0FF
Const ORYEL As Long = &HC0E0FF
Const YELLOWISH As Long = &HC0FFFF
Const GREENISH As Long = &HC0FFC0
Const LIGHTBLUISH As Long = &HFFFFC0
Const PURPLISH As Long = &HFFC0C0
Const PINKISH As Long = &HFFC0FF
Const WHITE As Long = &HFFFFFF
Dim arrColors As Variant

Private Sub Form_Load()
arrColors = Array(ORANGISH, ORYEL, YELLOWISH, LIGHTBLUISH,
PURPLISH, PINKISH, WHITE)
End Sub
Private Sub Timer1_Timer()
Static i
lblRunning.BackColor = arrColors(i)
i = i + 1
If i > 5 Then i = 0
End Sub
------------------------------------------------------

Here is my vb.net conversion
-----------------------------------------
constants...
Dim arrColors() As Long = {ORANGISH, ORYEL, YELLOWISH,
GREENISH, LIGHTBLUISH, PURPLISH, PINKISH, WHITE}

Private Sub Timer1_Tick(...) Handles Timer1.Tick
Static i As Integer
lblRunning.BackColor = CType(arrColors(i),
System.Drawing.Color)
i += 1
End Sub
-------------------------------------------------

The error message for vb.net says that it cannot convert a
long (arrColors(i)) to System.Drawing.Color. So how could
I achieve the same functionality in the vb.net app as in
the vb6 app above?

Thanks

Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
See the ColorTranslator.FromHTML method.

"B" <an*******@discussions.microsoft.com> wrote in message
news:1b****************************@phx.gbl...
Hello,

I am trying to migrate a vb6 app to vb.net. In one piece
of the vb6 app I have a label where the label backcolor
changes every 5 seconds on a timer. So I created an array
of colors as follows and then run the array in the timer
event in vb6. Not working in vb.net. How would I do this
in vb.net?

vb6 code:
-----------------------------------------
Const ORANGISH As Long = &HC0C0FF
Const ORYEL As Long = &HC0E0FF
Const YELLOWISH As Long = &HC0FFFF
Const GREENISH As Long = &HC0FFC0
Const LIGHTBLUISH As Long = &HFFFFC0
Const PURPLISH As Long = &HFFC0C0
Const PINKISH As Long = &HFFC0FF
Const WHITE As Long = &HFFFFFF
Dim arrColors As Variant

Private Sub Form_Load()
arrColors = Array(ORANGISH, ORYEL, YELLOWISH, LIGHTBLUISH,
PURPLISH, PINKISH, WHITE)
End Sub
Private Sub Timer1_Timer()
Static i
lblRunning.BackColor = arrColors(i)
i = i + 1
If i > 5 Then i = 0
End Sub
------------------------------------------------------

Here is my vb.net conversion
-----------------------------------------
constants...
Dim arrColors() As Long = {ORANGISH, ORYEL, YELLOWISH,
GREENISH, LIGHTBLUISH, PURPLISH, PINKISH, WHITE}

Private Sub Timer1_Tick(...) Handles Timer1.Tick
Static i As Integer
lblRunning.BackColor = CType(arrColors(i),
System.Drawing.Color)
i += 1
End Sub
-------------------------------------------------

The error message for vb.net says that it cannot convert a
long (arrColors(i)) to System.Drawing.Color. So how could
I achieve the same functionality in the vb.net app as in
the vb6 app above?

Thanks

Nov 21 '05 #2

P: n/a
B,

I think that this sample shows the most easy
(I took only three colors)

\\\
Private arrColors(2) As Drawing.Color
Private WithEvents mytimer As New Windows.Forms.Timer
Private Sub Form2_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
mytimer.Interval = 5000
mytimer.Enabled = True
arrColors(0) = Drawing.Color.Yellow
arrColors(1) = Drawing.Color.Blue
arrColors(2) = Drawing.Color.Red
Label1.BackColor = Drawing.Color.Red
End Sub
Private Sub mytimer_Tick(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles mytimer.Tick
Static i As Integer
Label1.BackColor = arrColors(i)
i = i + 1
If i > 2 Then i = 0
End Sub
///

I hope this helps

Cor

"B" <an*******@discussions.microsoft.com>
Hello,

I am trying to migrate a vb6 app to vb.net. In one piece
of the vb6 app I have a label where the label backcolor
changes every 5 seconds on a timer. So I created an array
of colors as follows and then run the array in the timer
event in vb6. Not working in vb.net. How would I do this
in vb.net?

vb6 code:
-----------------------------------------
Const ORANGISH As Long = &HC0C0FF
Const ORYEL As Long = &HC0E0FF
Const YELLOWISH As Long = &HC0FFFF
Const GREENISH As Long = &HC0FFC0
Const LIGHTBLUISH As Long = &HFFFFC0
Const PURPLISH As Long = &HFFC0C0
Const PINKISH As Long = &HFFC0FF
Const WHITE As Long = &HFFFFFF
Dim arrColors As Variant

Private Sub Form_Load()
arrColors = Array(ORANGISH, ORYEL, YELLOWISH, LIGHTBLUISH,
PURPLISH, PINKISH, WHITE)
End Sub
Private Sub Timer1_Timer()
Static i
lblRunning.BackColor = arrColors(i)
i = i + 1
If i > 5 Then i = 0
End Sub
------------------------------------------------------

Here is my vb.net conversion
-----------------------------------------
constants...
Dim arrColors() As Long = {ORANGISH, ORYEL, YELLOWISH,
GREENISH, LIGHTBLUISH, PURPLISH, PINKISH, WHITE}

Private Sub Timer1_Tick(...) Handles Timer1.Tick
Static i As Integer
lblRunning.BackColor = CType(arrColors(i),
System.Drawing.Color)
i += 1
End Sub
-------------------------------------------------

The error message for vb.net says that it cannot convert a
long (arrColors(i)) to System.Drawing.Color. So how could
I achieve the same functionality in the vb.net app as in
the vb6 app above?

Thanks

Nov 21 '05 #3

P: n/a
B
Thanks. That was the trick. (for the sake of my own
posterity I thought I would add this comment) Actually, to
keep the array of colors as numbers I had to do it this
way:

lblRunning.BackColor = ColorTranslator.FromOle(CType
(arrColors(i), Integer))

To use ColorTranslator.FromHtml I would have to set each
constant as a String and create a String array.

Const WHITE As String = "&HFFFFFF"
....

Either way works fine. Many thanks for your help.
-----Original Message-----
See the ColorTranslator.FromHTML method.

"B" <an*******@discussions.microsoft.com> wrote in messagenews:1b****************************@phx.gbl...
Hello,

I am trying to migrate a vb6 app to vb.net. In one piece of the vb6 app I have a label where the label backcolor
changes every 5 seconds on a timer. So I created an array of colors as follows and then run the array in the timer
event in vb6. Not working in vb.net. How would I do this in vb.net?

vb6 code:
-----------------------------------------
Const ORANGISH As Long = &HC0C0FF
Const ORYEL As Long = &HC0E0FF
Const YELLOWISH As Long = &HC0FFFF
Const GREENISH As Long = &HC0FFC0
Const LIGHTBLUISH As Long = &HFFFFC0
Const PURPLISH As Long = &HFFC0C0
Const PINKISH As Long = &HFFC0FF
Const WHITE As Long = &HFFFFFF
Dim arrColors As Variant

Private Sub Form_Load()
arrColors = Array(ORANGISH, ORYEL, YELLOWISH, LIGHTBLUISH, PURPLISH, PINKISH, WHITE)
End Sub
Private Sub Timer1_Timer()
Static i
lblRunning.BackColor = arrColors(i)
i = i + 1
If i > 5 Then i = 0
End Sub
------------------------------------------------------

Here is my vb.net conversion
-----------------------------------------
constants...
Dim arrColors() As Long = {ORANGISH, ORYEL, YELLOWISH,
GREENISH, LIGHTBLUISH, PURPLISH, PINKISH, WHITE}

Private Sub Timer1_Tick(...) Handles Timer1.Tick
Static i As Integer
lblRunning.BackColor = CType(arrColors(i),
System.Drawing.Color)
i += 1
End Sub
-------------------------------------------------

The error message for vb.net says that it cannot convert a long (arrColors(i)) to System.Drawing.Color. So how could I achieve the same functionality in the vb.net app as in
the vb6 app above?

Thanks

.

Nov 21 '05 #4

P: n/a
"B" <an*******@discussions.microsoft.com> schrieb:
I am trying to migrate a vb6 app to vb.net. In one piece
of the vb6 app I have a label where the label backcolor
changes every 5 seconds on a timer. So I created an array
of colors as follows and then run the array in the timer
event in vb6. Not working in vb.net. How would I do this
in vb.net?


Store your colors in 'Color' instances directly. You can use
'Color.FromArgb' to construct a color from RGB data, or you can use
predefined colors available in 'Color.*'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #5

P: n/a
B
Yes. This is the best way. I was thinking about FromArgB
but wasn't sure about the implementation. Here is what I
found on the net which gives me a whole variety of colors

Private m_Rnd As New Random

Public Function RandomRGBColor() As Color
Return Color.FromArgb(255, m_Rnd.Next(0, 255), _
m_Rnd.Next(0, 255), m_Rnd.Next(0, 255))
End Function

Thanks for this suggestion. I am amazed at how there are
so many different ways to accomplish something in vb.net.
-----Original Message-----
"B" <an*******@discussions.microsoft.com> schrieb:
I am trying to migrate a vb6 app to vb.net. In one piece of the vb6 app I have a label where the label backcolor
changes every 5 seconds on a timer. So I created an array of colors as follows and then run the array in the timer
event in vb6. Not working in vb.net. How would I do this in vb.net?
Store your colors in 'Color' instances directly. You can

use'Color.FromArgb' to construct a color from RGB data, or you can usepredefined colors available in 'Color.*'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

.

Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.