Solved

HTML color code

Posted on 1998-07-03
3
308 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

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…

758 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

22 Experts available now in Live!

Get 1:1 Help Now