Solved

How to convert rgb to long color in vb?

Posted on 2004-04-20
9
5,219 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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 …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now