Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > color equalivents


Reply
 
Thread Tools Display Modes
  #1  
Old 07-26-2006, 03:35 PM
Neon612 Neon612 is offline
Centurion
 
Join Date: Apr 2006
Posts: 124
Default color equalivents


I'm working on a color picker program and i need to find out how to get the rgb color to HTML, VB, Delphi, and C++.

I've got it separated into the rgb colors but to get HTML is the one i need the most.
__________________
"Sometimes lies were more dependable than the truth." -Ender Wiggin
"The power to cause pain is the only power that matters, the power to kill and destroy, because if you can't kill then you are always subject to those who can..." -Ender Wiggin
Reply With Quote
  #2  
Old 07-26-2006, 05:49 PM
Chris Ara Chris Ara is offline
Centurion
 
Join Date: Feb 2005
Posts: 176
Default

Heres a function to convert rgb to hex remember to include the number sign before the number in html "#FFCC99" the function does automatically include the number sign as well

Code:
 Public Function ConvertRGBtoHex(ByVal R As Integer, ByVal G As Integer, ByVal B As Integer) As String

       ConvertRGBtoHex = "#"
        Dim i As Integer
        Dim x As Integer
        Dim y As Integer

        '' find what (number * 16) + number2 = r to get the hex equivalent
        ' 0- 9 = 0-9 10 = a , 11 = b , 12 = c and so on to F

        For i = 0 To 15

            For x = 0 To 15

                If R = 16 * i + x Then
                    '''' find i value
                    If i = 0 Then
                        ConvertRGBtoHex += "0"
                    ElseIf i = 1 Then
                        ConvertRGBtoHex += "1"
                    ElseIf i = 2 Then
                        ConvertRGBtoHex += "2"
                    ElseIf i = 3 Then
                        ConvertRGBtoHex += "3"
                    ElseIf i = 4 Then
                        ConvertRGBtoHex += "4"
                    ElseIf i = 5 Then
                        ConvertRGBtoHex += "5"
                    ElseIf i = 6 Then
                        ConvertRGBtoHex += "6"
                    ElseIf i = 7 Then
                        ConvertRGBtoHex += "7"
                    ElseIf i = 8 Then
                        ConvertRGBtoHex += "8"
                    ElseIf i = 9 Then
                        ConvertRGBtoHex += "9"
                    ElseIf i = 10 Then
                        ConvertRGBtoHex += "a"
                    ElseIf i = 11 Then
                        ConvertRGBtoHex += "b"
                    ElseIf i = 12 Then
                        ConvertRGBtoHex += "c"
                    ElseIf i = 13 Then
                        ConvertRGBtoHex += "d"
                    ElseIf i = 14 Then
                        ConvertRGBtoHex += "e"
                    ElseIf i = 15 Then
                        ConvertRGBtoHex += "f"
                    End If

                    ''''''''' find x value
                    If x = 0 Then
                        ConvertRGBtoHex += "0"
                    ElseIf x = 1 Then
                        ConvertRGBtoHex += "1"
                    ElseIf x = 2 Then
                        ConvertRGBtoHex += "2"
                    ElseIf x = 3 Then
                        ConvertRGBtoHex += "3"
                    ElseIf x = 4 Then
                        ConvertRGBtoHex += "4"
                    ElseIf x = 5 Then
                        ConvertRGBtoHex += "5"
                    ElseIf x = 6 Then
                        ConvertRGBtoHex += "6"
                    ElseIf x = 7 Then
                        ConvertRGBtoHex += "7"
                    ElseIf x = 8 Then
                        ConvertRGBtoHex += "8"
                    ElseIf x = 9 Then
                        ConvertRGBtoHex += "9"
                    ElseIf x = 10 Then
                        ConvertRGBtoHex += "a"
                    ElseIf x = 11 Then
                        ConvertRGBtoHex += "b"
                    ElseIf x = 12 Then
                        ConvertRGBtoHex += "c"
                    ElseIf x = 13 Then
                        ConvertRGBtoHex += "d"
                    ElseIf x = 14 Then
                        ConvertRGBtoHex += "e"
                    ElseIf x = 15 Then
                        ConvertRGBtoHex += "f"
                    End If

                End If

            Next x

        Next i

        For i = 0 To 15

            For x = 0 To 15

                If G = 16 * i + x Then
                    '''' find i value
                    If i = 0 Then
                        ConvertRGBtoHex += "0"
                    ElseIf i = 1 Then
                        ConvertRGBtoHex += "1"
                    ElseIf i = 2 Then
                        ConvertRGBtoHex += "2"
                    ElseIf i = 3 Then
                        ConvertRGBtoHex += "3"
                    ElseIf i = 4 Then
                        ConvertRGBtoHex += "4"
                    ElseIf i = 5 Then
                        ConvertRGBtoHex += "5"
                    ElseIf i = 6 Then
                        ConvertRGBtoHex += "6"
                    ElseIf i = 7 Then
                        ConvertRGBtoHex += "7"
                    ElseIf i = 8 Then
                        ConvertRGBtoHex += "8"
                    ElseIf i = 9 Then
                        ConvertRGBtoHex += "9"
                    ElseIf i = 10 Then
                        ConvertRGBtoHex += "a"
                    ElseIf i = 11 Then
                        ConvertRGBtoHex += "b"
                    ElseIf i = 12 Then
                        ConvertRGBtoHex += "c"
                    ElseIf i = 13 Then
                        ConvertRGBtoHex += "d"
                    ElseIf i = 14 Then
                        ConvertRGBtoHex += "e"
                    ElseIf i = 15 Then
                        ConvertRGBtoHex += "f"
                    End If

                    ''''''''' find x value
                    If x = 0 Then
                        ConvertRGBtoHex += "0"
                    ElseIf x = 1 Then
                        ConvertRGBtoHex += "1"
                    ElseIf x = 2 Then
                        ConvertRGBtoHex += "2"
                    ElseIf x = 3 Then
                        ConvertRGBtoHex += "3"
                    ElseIf x = 4 Then
                        ConvertRGBtoHex += "4"
                    ElseIf x = 5 Then
                        ConvertRGBtoHex += "5"
                    ElseIf x = 6 Then
                        ConvertRGBtoHex += "6"
                    ElseIf x = 7 Then
                        ConvertRGBtoHex += "7"
                    ElseIf x = 8 Then
                        ConvertRGBtoHex += "8"
                    ElseIf x = 9 Then
                        ConvertRGBtoHex += "9"
                    ElseIf x = 10 Then
                        ConvertRGBtoHex += "a"
                    ElseIf x = 11 Then
                        ConvertRGBtoHex += "b"
                    ElseIf x = 12 Then
                        ConvertRGBtoHex += "c"
                    ElseIf x = 13 Then
                        ConvertRGBtoHex += "d"
                    ElseIf x = 14 Then
                        ConvertRGBtoHex += "e"
                    ElseIf x = 15 Then
                        ConvertRGBtoHex += "f"
                    End If

                End If

            Next x

        Next i

        For i = 0 To 15

            For x = 0 To 15

                If B = 16 * i + x Then
                    '''' find i value
                    If i = 0 Then
                        ConvertRGBtoHex += "0"
                    ElseIf i = 1 Then
                        ConvertRGBtoHex += "1"
                    ElseIf i = 2 Then
                        ConvertRGBtoHex += "2"
                    ElseIf i = 3 Then
                        ConvertRGBtoHex += "3"
                    ElseIf i = 4 Then
                        ConvertRGBtoHex += "4"
                    ElseIf i = 5 Then
                        ConvertRGBtoHex += "5"
                    ElseIf i = 6 Then
                        ConvertRGBtoHex += "6"
                    ElseIf i = 7 Then
                        ConvertRGBtoHex += "7"
                    ElseIf i = 8 Then
                        ConvertRGBtoHex += "8"
                    ElseIf i = 9 Then
                        ConvertRGBtoHex += "9"
                    ElseIf i = 10 Then
                        ConvertRGBtoHex += "a"
                    ElseIf i = 11 Then
                        ConvertRGBtoHex += "b"
                    ElseIf i = 12 Then
                        ConvertRGBtoHex += "c"
                    ElseIf i = 13 Then
                        ConvertRGBtoHex += "d"
                    ElseIf i = 14 Then
                        ConvertRGBtoHex += "e"
                    ElseIf i = 15 Then
                        ConvertRGBtoHex += "f"
                    End If

                    ''''''''' find x value
                    If x = 0 Then
                        ConvertRGBtoHex += "0"
                    ElseIf x = 1 Then
                        ConvertRGBtoHex += "1"
                    ElseIf x = 2 Then
                        ConvertRGBtoHex += "2"
                    ElseIf x = 3 Then
                        ConvertRGBtoHex += "3"
                    ElseIf x = 4 Then
                        ConvertRGBtoHex += "4"
                    ElseIf x = 5 Then
                        ConvertRGBtoHex += "5"
                    ElseIf x = 6 Then
                        ConvertRGBtoHex += "6"
                    ElseIf x = 7 Then
                        ConvertRGBtoHex += "7"
                    ElseIf x = 8 Then
                        ConvertRGBtoHex += "8"
                    ElseIf x = 9 Then
                        ConvertRGBtoHex += "9"
                    ElseIf x = 10 Then
                        ConvertRGBtoHex += "a"
                    ElseIf x = 11 Then
                        ConvertRGBtoHex += "b"
                    ElseIf x = 12 Then
                        ConvertRGBtoHex += "c"
                    ElseIf x = 13 Then
                        ConvertRGBtoHex += "d"
                    ElseIf x = 14 Then
                        ConvertRGBtoHex += "e"
                    ElseIf x = 15 Then
                        ConvertRGBtoHex += "f"
                    End If

                End If

            Next x

        Next i

    End Function
Reply With Quote
  #3  
Old 07-26-2006, 09:11 PM
OnErr0r's Avatar
OnErr0r OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,686
Default

The Hex$ function would help considerably.

Code:
Public Function RGBtoHex(ByVal R As Byte, ByVal G As Byte, ByVal B As Byte) As String RGBToHex = "#" & Right$("0" & Hex$(R), 2) & Right$("0" & Hex$(G), 2) & Right$("0" & Hex$(B), 2) End Function
__________________
Quis custodiet ipsos custodues.
Reply With Quote
  #4  
Old 07-27-2006, 10:30 AM
4x2y 4x2y is offline
Contributor
 
Join Date: Sep 2005
Posts: 565
Default

and this to convert HTML color to RGB
Code:
Public Function HexToRGB(ByVal strHex As String) As Variant HexToRGB = Array( _ Val("&H" & Mid$(strHex, 2, 2)), _ Val("&H" & Mid$(strHex, 4, 2)), _ Val("&H" & Mid$(strHex, 6, 2))) End Function
__________________
Visit my site
Reply With Quote
  #5  
Old 07-28-2006, 03:08 PM
Neon612 Neon612 is offline
Centurion
 
Join Date: Apr 2006
Posts: 124
Default

How do i use the function (i think its calling the function)?
I've never used one before so i'm at a loss of what to do.
__________________
"Sometimes lies were more dependable than the truth." -Ender Wiggin
"The power to cause pain is the only power that matters, the power to kill and destroy, because if you can't kill then you are always subject to those who can..." -Ender Wiggin
Reply With Quote
  #6  
Old 07-28-2006, 03:40 PM
OnErr0r's Avatar
OnErr0r OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,686
Default

Code:
Dim s As String s = RGBtoHex(255, 255, 255) Debug.Print s
__________________
Quis custodiet ipsos custodues.
Reply With Quote
  #7  
Old 07-28-2006, 03:46 PM
Neon612 Neon612 is offline
Centurion
 
Join Date: Apr 2006
Posts: 124
Default

Okay thanx that works
Does anyone have an idea of how to convert RGB to VB color?
__________________
"Sometimes lies were more dependable than the truth." -Ender Wiggin
"The power to cause pain is the only power that matters, the power to kill and destroy, because if you can't kill then you are always subject to those who can..." -Ender Wiggin
Reply With Quote
  #8  
Old 07-29-2006, 12:07 AM
OnErr0r's Avatar
OnErr0r OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,686
Default

If you have separate R, G and B, use the RGB function.
__________________
Quis custodiet ipsos custodues.
Reply With Quote
  #9  
Old 07-29-2006, 04:18 PM
Neon612 Neon612 is offline
Centurion
 
Join Date: Apr 2006
Posts: 124
Default

No wat i'm talkign about is the VB number
EX:

RGB 255, 255, 255 = white
HEX #FFFFFF = white
VB &H00FFFFFF& = white
__________________
"Sometimes lies were more dependable than the truth." -Ender Wiggin
"The power to cause pain is the only power that matters, the power to kill and destroy, because if you can't kill then you are always subject to those who can..." -Ender Wiggin
Reply With Quote
  #10  
Old 07-29-2006, 04:24 PM
OnErr0r's Avatar
OnErr0r OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,686
Default

Code:
"&H" & Right$("0000000" & Hex$(lColor), 8) & "&"
__________________
Quis custodiet ipsos custodues.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->