Kak RGB превратить в Html? - VB
Формулировка задачи:
Kak RGB превратить в Html?
Решение задачи: «Kak RGB превратить в Html?»
textual
Листинг программы
Public Const RedPart = 0 Public Const GreenPart = 1 Public Const BluePart = 2 Public Function HTML(Red As Integer, Green As Integer, Blue As Integer) As String HTML = '' If Len(Hex$(Red)) = 1 Then HTML = HTML & '0' & Hex$(Red) Else HTML = HTML & Hex$(Red) End If If Len(Hex$(Green)) = 1 Then HTML = HTML & '0' & Hex$(Green) Else HTML = HTML & Hex$(Green) End If If Len(Hex$(Blue)) = 1 Then HTML = HTML & '0' & Hex$(Blue) Else HTML = HTML & Hex$(Blue) End If End Function Public Function UnRGB(RGBCol As Long, Part As Integer) As Integer 'Part: 0=Red, 1=Green, 2=Blue Select Case Part Case 0 UnRGB = RGBCol And &HFF 'mask 000000000000000011111111 and shift bits right Case 1 UnRGB = (RGBCol And &HFF00) / &HFF 'mask 000000001111111100000000 and shift bits right Case 2 UnRGB = (RGBCol And &HFF0000) / &HFFFF 'mask 111111110000000000000000 and shift bits right End Select End Function Public Function UnHTML(HTMLCol As String, Part As Integer) As Integer 'Part: 0=Red, 1=Green, 2=Blue Select Case Part Case 0 UnHTML = (CLng('&H' & HTMLCol) And &HFF0000) / &HFFFF 'mask 111111110000000000000000 and shift bits right Case 1 UnHTML = (CLng('&H' & HTMLCol) And &HFF00) / &HFF 'mask 000000001111111100000000 and shift bits right Case 2 UnHTML = CLng('&H' & HTMLCol) And &HFF 'mask 000000000000000011111111 and shift bits right End Select End Function Public Function RGB2HTML(RGBCol As Long) As String RGB2HTML = HTML(UnRGB(RGBCol, RedPart), UnRGB(RGBCol, GreenPart), UnRGB(RGBCol, BluePart)) End Function Public Function HTML2RGB(HTMLCol As String) As Long HTML2RGB = RGB(UnHTML(HTMLCol, RedPart), UnHTML(HTMLCol, _ GreenPart), UnHTML(HTMLCol, BluePart)) End Function
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д