by Charlie Wilson (1 Submission)
Category: Internet/HTML
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (2 Votes)
This code takes the common dialog color, extracts the R, G, B values, and
converts each value to the correct HEX equivilant supported by HTML.
Inputs
Function requires a common dialog control color being selected and passed to the
function
Assumes
You must add the common dialog control to your application. After the ShowOpen event
occurs, pass the color selected by the user to the function:
Dim sColHex as String
sColHex = HexRGB(cdlCont.color)
Code Returns
Function returns properly formatted HEX color value for HTML
API DeclarationsNone
Private Function HexRGB(lCdlColor As Long)
Dim lCol As Long
Dim iRed, iGreen, iBlue As Integer
Dim vHexR, vHexG, vHexB As Variant
'Break out the R, G, B values from the common dialog color
lCol = lCdlColor
iRed = lCol Mod &H100
lCol = lCol \ &H100
iGreen = lCol Mod &H100
lCol = lCol \ &H100
iBlue = lCol Mod &H100
'Determine Red Hex
vHexR = Hex(iRed)
If Len(vHexR) < 2 Then
vHexR = "0" & vHexR
End If
'Determine Green Hex
vHexG = Hex(iGreen)
If Len(vHexG) < 2 Then
vHexG = "0" & iGreen
End If
'Determine Blue Hex
vHexB = Hex(iBlue)
If Len(vHexB) < 2 Then
vHexB = "0" & vHexB
End If
'Add it up, return the function value
HexRGB = "#" & vHexR & vHexG & vHexB
End Function