?
Solved

Need to put 'color' hex value in a text box

Posted on 2003-02-21
3
Medium Priority
?
225 Views
Last Modified: 2013-12-25
All,
I put a common dialog control on my form.
See below code.
I click a command button (cmdColor01, brings up Common Dialog Color Selection)to pick a color.
I select a color and set the background of a text box (txtShowColor01) to show the color choice for comparison to the other 3, there will be 4 total.
I want a text box (txtColorValue.Text) to then display the HEX value of the color choice so I can later on in the program throw that value into an HTML page replacing a place holder the colors a table, some text or whatever.
What do I put where the '??????' are to get the HEX value of the color I selected?


Private Sub cmdColor01_Click()
cmd.ShowColor
txtShowColor01.BackColor = cmd.Color
txtColorValue.Text = ??????
End Sub

Thanks in advance,
Ploppin
0
Comment
Question by:ploppin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 400 total points
ID: 7993845
Something like this:

txtColorValue.Text = GetHTMLColor(cmd.Color)

And also you need this function:

Private Function GetHTMLColor(ByVal Color As Long) As String
    Dim strHColor As String
    strHColor = "000000" & Hex(Color)
    strHColor = Right(strHColor, 6)
    strR = Left(strHColor, 2)
    strG = Mid(strHColor, 3, 2)
    strB = Mid(strHColor, 5, 2)
    GetHTMLColor = strB & strG & strR
End Function

Which converts the long value returned by the common dialog to an RGB string suitable for use in HTML.
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 7993888
either:

cmd.ShowColor
txtShowColor01.BackColor = cmd.Color
txtColorValue.Text = Hex(cmd.Color)

which wioll show a valur like 80FF or 80F46F or whatever color value that was chosen.

or, if you want to show that it is HEX:

cmd.ShowColor
txtShowColor01.BackColor = cmd.Color
txtColorValue.Text = "&H" & Hex(cmd.Color)


which would show it as

&H80FF  or &H80F46F  or whatever color value that was chosen

AW
0
 

Author Comment

by:ploppin
ID: 7995057
Worked like a charm. Thanks.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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.
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…
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…
Suggested Courses

770 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