Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Colour Array 1

Status
Not open for further replies.

JackSkellington

Technical User
Jul 28, 2005
86
GB
I have a colour array that I am building via a case statement i.e.

Code:
Select Case arrColours.Length

Case 1

arrColours(0) = System.Drawing.Color = Green

Case 2

arrColours(0) = System.Drawing.Color = Green
arrColours(1) = System.Drawing.Color = Green

This is replicate up to 7 adding a new colour each time, is there a nicer way/more efficient way to do this?
 
chrissie1, isn't he trying to ask for an answer other than 'Yep' :-D

JackSkellington, It wasn't quite clear that you where tring to ask for help...

Why don't you:
Code:
For Count As Integer = 0 To arrColours.Length - 1

   arrColours(Count) = Color.Green

Next


 
Very clever of you chrissie1

Sorry there is a mistake in the code as each colour should be different i.e

Code:
Select Case arrColours.Length

Case 1

arrColours(0) = System.Drawing.Color = Green

Case 2

arrColours(0) = System.Drawing.Color = Green
arrColours(1) = System.Drawing.Color = Orange
 
You see, I knew you where going to say that and this changes the answer to no. Except if the colors will always be in the same order.

Christiaan Baes
Belgium

"My new site" - Me
 
Like Chrissie said, if the colors are always in the same order:

1: Green
2: Green Orange
3: Green Orange Red
...

You could create one static color array with all of the colors, in order. Then, instead of a case statement, just loop through the arrColours array and populate each element with the coresponding element from the static color array.

If they are not the same, you could create all of the different color arrays and add them to a hash table. Use the length of the array as the key for the table. Then, instead of a case statement, create another color array and set it equal to the hash table item with the key that equals the arrColours.length. Then just loop through the array as mentioned above.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
All but the last colours will be in order i.e. the final colour will always be black.
 
So something like this:

Code:
dim arrStaticColors() as color = {Green, Orange, Puple, Red, Yellow}

dim i as integer
for i = 0 to arrColours.length-2
  arrcolours(i) = arrstaticcolors(i)
next

arrColours(arrColours.length-1) = bloack

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top