Home > How-To Library > Coding Basics

How to converte color value(longint) into RGB value.

**************************************************************** * © 2007 CodeItBetter http://www.codeitbetter.com * * This notice MUST stay intact for legal use * ****************************************************************
Public Function rgbcolortovalue(rslt As Long) As String Dim tmphasil1 As Byte Dim tmphasil2 As Byte Dim tmphasil1a As Byte Dim tmphasil1b As Byte Dim tmphasil1c As Long If rslt < 256 Then rgbcolortovalue = Trim(Format(rslt, "0##")) + ",000,000" ElseIf (rslt > 256) And (rslt < 65536) Then tmphasil1 = rslt Mod 256 tmphasil2 = Int(rslt / 256) rgbcolortovalue = Trim(Format(tmphasil1, "0##")) + "," + Trim(Format(tmphasil2, "0##")) + ",000" ElseIf rslt > 65535 Then tmphasil2 = Int(rslt / 65536) tmphasil1c = rslt Mod 65536 If tmphasil1c < 256 Then rgbcolortovalue = Trim(Format(tmphasil1c, "0##")) + ",000," + Trim(Format(tmphasil2, "0##")) Else tmphasil1a = tmphasil1c Mod 256 tmphasil1b = Int(tmphasil1c / 256) rgbcolortovalue = Trim(Format(tmphasil1a, "0##")) + "," + Trim(Format(tmphasil1b, "0##")) + "," + _ Trim(Format(tmphasil2, "0##")) End If End If End Function

If you would like to submit your code here please us. Do not forget to mention your name. We are always thankful to each and everyone of you who submitted their code here.