Solved

HTML color code

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…

813 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

10 Experts available now in Live!

Get 1:1 Help Now