Solved

How to convert rgb to long color in vb?

Posted on 2004-04-20
9
5,374 Views
Last Modified: 2012-08-14
I'm using some shapes in my vb form.

I need to change background color, but vb use long color like this &H00E0E0E0&
While I use photoshop to get my color right in rgb color and html color #FFFFFF

Is there any tool to convert rgb or html color to vb color?

I know I can use command like:
s1.BackColor = RGB(239, 231, 222)
I don't like it, i want in design time.
0
Comment
Question by:dodyrw
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 1

Expert Comment

by:stewi
ID: 10867707
iColor=&hccccff 'the color in hex same syntax as html
s1.BackColor=rgb((iColor And &HFF),((iColor And &HFF00&) \ 256),((iColor And &HFF0000) \ 65536))

Reguards
Stewi
0
 
LVL 1

Expert Comment

by:vware
ID: 10867745
You can use either of those 2, simply create a new form, place the following code into it. Adjust the parameters to your needs.

Private Sub Form_Load()
    MsgBox GetVBFromRGB(10, 10, 10)
End Sub

Private Function GetHexFromRGB(ByVal RVal As Byte, ByVal GVal As Byte, ByVal BVal As Byte) As String
    Dim TmpHex As String
   
    TmpHex = Left("0" & Hex(BVal), 2) & _
             Left("0" & Hex(GVal), 2) & _
             Left("0" & Hex(RVal), 2)
    GetHexFromRGB = "&H" & TmpHex & "&"
End Function

Private Function GetVBFromRGB(ByVal RVal As Byte, ByVal GVal As Byte, ByVal BVal As Byte) As String
    Dim TmpHex As String
   
    TmpHex = Left("0" & Hex(RVal), 2) & _
             Left("0" & Hex(GVal), 2) & _
             Left("0" & Hex(BVal), 2)
    GetVBFromRGB = "#" & TmpHex
End Function
0
 

Author Comment

by:dodyrw
ID: 10868041
Sorry I think that is not the answer i need.
&H00E0E0E0& is not hex.

anyone?
HTML to VB color
or RGB to VB color is fine.

anyway, thanks for your help guys.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Accepted Solution

by:
stewi earned 500 total points
ID: 10868095
... &H00E0E0E0& is not hex...
yes it is...
&H is the VB-way to say its a hex
00 is just zeros
E0 if the hex for blue
E0 is the hex for green
E0 is the hex for red
& is the VB-way for long integer

Reguard
Stewi
0
 
LVL 1

Expert Comment

by:vware
ID: 10868142
sorry to disappoint you dodyrw, but this IS hex... stewi explained that pretty nicely... apart from that, you can still use the GetVBFromRGB function, which converts RGB to VB. just in case you dont trust the Hex that comes from the GetHexFromRGB function...
0
 

Author Comment

by:dodyrw
ID: 10868164
:) sorry I'm to0 haste, lol
it's hex.   :)

vb use 8 digit hex: &H00E0E0E0&
but those codes produce only 6 digits.


Got it! VB use reverse RGB
#EFE7DE
--> &H00DEE7EF

:D
thanks.
0
 
LVL 1

Expert Comment

by:stewi
ID: 10868184
Yes, now your on the right track.

Stewi
0
 
LVL 1

Expert Comment

by:vware
ID: 10868856
thats why i built the example i posted like this... so you could see the re-ordering of the values...
0
 

Expert Comment

by:MikeEast
ID: 11192735
Hi all..

I guess this is the answer to all doubts:

myControl.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff")

That is for VB.NET of course, but I just wanted to add the comment here, since I found this page looking for that very answer...

::m
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question