Solved

How to convert rgb to long color in vb?

Posted on 2004-04-20
9
5,571 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month4 days, 3 hours left to enroll

630 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