VB icon

Convert Color

Email
Submitted on: 1/31/2015 1:59:00 AM
By: Zap The Dingbat (from psc cd)  
Level: Beginner
User Rating: By 2 Users
Compatibility: VB 5.0, VB 6.0, VBA MS Access, VBA MS Excel
Views: 636
 
     Convert color codes RGB to VB RGB to HTML VB to RGB VB to HTML HTML to RGB HTML to VB
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Convert Color
' Description:Convert color codes
RGB to VB
RGB to HTML
VB to RGB
VB to HTML
HTML to RGB
HTML to VB
' By: Zap The Dingbat (from psc cd)
'
' Inputs:colConvertType: type of convertion
strColor: string containing color value. if rgb then spesify r,g,b as 3 values
'
' Returns:string containing new color value. 
If RGB then returns 1 string delimited by ","
'**************************************

Public Enum colConvertType
colRGBtoVB = 0
colRGBtoHTML = 1
colVBtoRGB = 2
colVBtoHTML = 3
colHTMLtoRGB = 4
colHTMLtoVB = 5
End Enum
Function convertColor(convert As colConvertType, ParamArray strColor()) As String
Select Case convert
Case colRGBtoHTML
convertColor = Left("00" & Hex(strColor(0)), 2)
convertColor = Left("00" & convertColor & Hex(strColor(1)), 2)
convertColor = Left("00" & convertColor & Hex(strColor(2)), 2)
Case colRGBtoVB
convertColor = RGB(strColor(0), strColor(1), strColor(2))
Case colVBtoRGB
convertColor = Right("000000" & Hex(strColor(0)), 6)
r = CByte("&h" & Mid(convertColor, 5, 2))
g = CByte("&h" & Mid(convertColor, 3, 2))
b = CByte("&h" & Mid(convertColor, 1, 2))
convertColor = r & "," & g & "," & b
Case colVBtoHTML
convertColor = Right("000000" & Hex(strColor(0)), 6)
r = Mid(convertColor, 5, 2)
g = Mid(convertColor, 3, 2)
b = Mid(convertColor, 1, 2)
convertColor = r & g & b
Case colHTMLtoRGB
convertColor = Right("000000" & Hex(strColor(0)), 6)
r = CByte("&h" & Mid(convertColor, 1, 2))
g = CByte("&h" & Mid(convertColor, 3, 2))
b = CByte("&h" & Mid(convertColor, 5, 2))
convertColor = r & "," & g & "," & b
Case colHTMLtoVB
convertColor = Right("000000" & Hex(strColor(0)), 6)
r = CByte("&h" & Mid(convertColor, 1, 2))
g = CByte("&h" & Mid(convertColor, 3, 2))
b = CByte("&h" & Mid(convertColor, 5, 2))
convertColor = RGB(r, g, b)
End Select
End Function


Other 2 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.