Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 228
  • Last Modified:

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

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
ploppin
Asked:
ploppin
1 Solution
 
TimCotteeCommented:
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
 
Arthur_WoodCommented:
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
 
ploppinAuthor Commented:
Worked like a charm. Thanks.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now