Solved

HTML color code

Posted on 1998-07-03
3
317 Views
Last Modified: 2012-06-21
How can I convert my Visual Basic color code into HTML color code?
Using the HEX function doesn't always get the colors that I chose.
Does anyone know how to get the correct colors?
0
Comment
Question by:captain_needa
3 Comments
 
LVL 1

Expert Comment

by:MAVERICK
ID: 1464909
Are you using the VB default colors???

Can u provide further details on your application

0
 

Expert Comment

by:xlunax
ID: 1464910
I dont even know if VB uses the same HEX codes as HTML at all.  They may be incompatible with each other.  What you may need to do is write a database with as many colors as you know the HTML HEX string for and have VB search it for what you are looking for.  Unfortunatly that will be VERY LARGE.  =)
0
 
LVL 6

Accepted Solution

by:
alamo earned 100 total points
ID: 1464911
There are 3 possible reasons:

Most significantly, VB's color colde and HTML's color code is different. In VB ff0000 is blue and in html it's red, whereas in VB 0000ff is red and in html it's blue. Green is the same in both.

Secondly, VB can use Windows system colors. A system color is a color like &H80000001 where VB looks up the color settings on the particular machine in use.

Finally - browsers sometimes can't display the exact color shade a page has, so it does its best. This is most often true on displays with limited colors. There is nothing you can do about this except try to choose colors which will still look good if they aren't quite right. (And choose colors which almost all displays can handle).

The following function will convert a VB color code to the corresponding html code:

Declare Function GetSysColor Lib "user32" (ByVal nIndex As Long) As Long

Public Function HTMLColor(ByVal vbcolor As Long) As Long
 If vbcolor And &H80000000 Then
  vbcolor = GetSysColor(vbcolor And &HFFFFFF)
 End If
 HTMLColor = (vbcolor And &HFF0000) / &H10000 + (vbcolor And &HFF00&) + (vbcolor And &HFF&) * &H10000
End Function

Good luck!
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

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…
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 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…

929 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

14 Experts available now in Live!

Get 1:1 Help Now