Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...This site is awesome!...Things I have been trying to figure out for weeks, I got the answer in hours!..."

Geography

Where in the world do Tek-Tips members come from?
Andrzejek (Programmer)
17 Jul 12 9:49

I have this small table in ORACLE where I want to keep colors:

COLOR_ID COLOR_DESC

0........White
1........Blue
2........Green
3........Salmon


I know I can use:
System.Drawing.ColorTranslator.FromWin32(&HFFFFFF&)

and &HFFFFFF& gives me White color (&HFF0000& gives me Blue, etc.)

I want to keep colors somehow in my data base to avoid Select Case statements or a bunch of IF statements in my code.

Two questions:
1. Is that the best way to approach colors?
2. How can I keep Colors in data base? What format should the column be? String? Integer?

Have fun.

---- Andy

Antzelinaki (Programmer)
17 Jul 12 12:45
What about if you add a string field named ColourValue in your table that will keep the value of each colour as &HFFFFFF& for example???
I disagree with integer type... you can convert the type of the field if you need it in your code. You don't have to remove COLOR_DESC field because it makes you clear which value of colour corresponds to the proper colour. The what you will do is to retrieve the value of the field you want each time from your database and you will achieve it via a sql query for example select ColourValue from colours where Colour_Desc = "Blue" you will store the result of the query to a variable. You can use a combo box with the colours you want blue, green, white, etc and if you can compare the value of combobox with the result of query.

Private Sub combo_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles combo.SelectedIndexChanged
dim colour, tempColour as string
colour = combo.Items.Item(combo.SelectedIndex))
' here you will put your query and your code to open your recordset etc... I give you the query.
tempColour = 'select ColourValue from Colours where Colour_Desc=' & colour
System.Drawing.ColorTranslator.FromWin32(tempColour)
end sub
so you will get the colour you want each time without use if, or select case statement. Hope it helps. Have fun dazed
ZmrAbdulla (TechnicalUser)
18 Jul 12 6:48
You can get all the known colors to a combobox, listbox or an array

CODE --> VB.NET

Imports System.Drawing 

CODE --> VB.NET

Sub LoadColorsInAListBox(ByVal lstColor1 As ListBox)
        For kColor = KnownColor.AliceBlue To KnownColor.YellowGreen
            lstColor1.Items.Add(kColor)
        Next
    End Sub 

Zameer Abdulla

Andrzejek (Programmer)
19 Jul 12 12:39
Antzelinaki,

Your code:
System.Drawing.ColorTranslator.FromWin32(tempColour)

gives me an error: Conversion from string "&H00FFFFFF&" to type 'Integer' is not valid.

Have fun.

---- Andy

Andrzejek (Programmer)
19 Jul 12 13:54

If Integer it wants, the Integer it gets: smile

I have found the equivalents as Integers:

CODE

ID      COLOR_DESC   COLOR_VALUE       COLOR_INT
0       White        &H00FFFFFF&       16777215
1       Yellow       &H0000FFFF&          65535
2       Green        &H0000FF00&          65280
3       Salmon       &H000080FF&          33023 

And it works smile

I just may drop COLOR_VALUE column...

Have fun.

---- Andy

Antzelinaki (Programmer)
21 Jul 12 8:33
you can use the val function to convert string to integer too!!!!

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close