Solved

How to convert rgb to long color in vb?

Posted on 2004-04-20
9
5,148 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

708 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

12 Experts available now in Live!

Get 1:1 Help Now