473,806 Members | 2,895 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

prob with array of colors from vb6 to vb.net

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.Back Color = 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.Back Color = 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
5 7352
See the ColorTranslator .FromHTML method.

"B" <an*******@disc ussions.microso ft.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.Back Color = 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.Back Color = 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
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.T imer
Private Sub Form2_Load(ByVa l sender As Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
mytimer.Interva l = 5000
mytimer.Enabled = True
arrColors(0) = Drawing.Color.Y ellow
arrColors(1) = Drawing.Color.B lue
arrColors(2) = Drawing.Color.R ed
Label1.BackColo r = Drawing.Color.R ed
End Sub
Private Sub mytimer_Tick(By Val sender As Object, _
ByVal e As System.EventArg s) Handles mytimer.Tick
Static i As Integer
Label1.BackColo r = arrColors(i)
i = i + 1
If i > 2 Then i = 0
End Sub
///

I hope this helps

Cor

"B" <an*******@disc ussions.microso ft.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.Back Color = 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.Back Color = 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
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.Back Color = 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*******@disc ussions.microso ft.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.Back Color = 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.Back Color = 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
"B" <an*******@disc ussions.microso ft.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
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*******@disc ussions.microso ft.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.FromArg b' 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
4150
by: me | last post by:
good day, i found this message: and i want to know more about it too. ========================================== Hey all, example: $s_Colors="0066FF;0066CC;3366CC;0033FF;003399;003366;99CCFF;3399FF;0099FF;66
5
2716
by: howdy | last post by:
Hi all, I'm trying to rotate 5 images which load from the server. My script loads the images but when i move to the end of my array i want to cycle throught the array again so that the images will load again in succession. At the moment the images load through once and then stop on the first one. How can i make my code constantly cycle throuhg the images and not stop once it has gone through one time? Here is my current code: <SCRIPT...
5
1592
by: Brett | last post by:
Sorry for the rookie question.... If I have a pointer array (for example): char *colors = { "blue", "green" }; and I want to add yellow to this array later in my code....how would I do
2
1659
by: Roger | last post by:
Hi, I'm trying to populate an array with color names. I keep getting an error. Here is the line that fails: Dim Colors As String() = Enum.GetValues(enumColor.GetType())
5
14546
by: Stick | last post by:
Hi, I normally program in C++, and I'm trying to write this little tool in C#, but I quickly realized that I can't use pointers, so instead I need to create an array of 3 Color 's private Color cDay; private Color cNight; private Color cLuminous;
2
1433
by: jhetfield18 | last post by:
I have to write a program for the university as a weekly project that gets an int array as an input and the contents can only be 0 and 1.Its supposed to be a maze solver.1 as wall and you can move on 0.But after a move in any direction it has to mark the previous location with a '*'.And I need to use some functions: 1)void TurnLeft 2)void TurnRight 3)void MoveForward 4)int IsFacingWall 5)int IsOutside(in which everything will be done...
3
3448
by: rob | last post by:
Hello, If I have an array made up of a bunch of key =value pairs, how can I pass the values of each key as an argument to a function, given that the number of items in the array are not static (i.e: sometimes there's one item, sometimes there's two)? For example, if I have the following array: $list = array('sky' ='blue', 'grass' ='green');
9
1912
by: JackpipE | last post by:
I need to create multidimensional array with arrays inside of it. database name | value1 | value2 john | red | 45 john | red | 56 john | yellow | 11 mike | blue | 23 mike | black | 41
2
1505
by: pcdinh | last post by:
I tried to make a javascript function based on Function object and assign it an outside data, expecting that that function will return a string with data populated. <script> // Data var colors = // Function body with some variables var functionBody = "alert(this.colors); var __out = '<p>Here is a list of '; this.colors.length; __out += ' colors: <ul'; for (var i=0;
0
9719
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10372
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10110
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9187
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6877
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5546
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5682
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3851
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.