Java script function to convert RGB to BV6 color

I have to store some color values in a sql table from a webpage and I need a function that will convert either RGB or HEX color values to the VB6 color format.
dssisupportAsked:
Who is Participating?
 
GwynforWebCommented:
Taking VB6 format as 0xBBGGRR then RGB to VB6 is

<script>
function pad(number) {
  str = '' + number;
  while (str.length < 2) str = '0' + str;
  return str;
}

function toVBColor(r,g,b) { 
   return '0x'+ pad(b.toString(16)) + pad(g.toString(16)) + pad(r.toString(16)); 
}

</script>

Open in new window

I am not exactly sure this is what you want.
0
 
dssisupportAuthor Commented:
That is almost it but I need the VB Long format instead of 0xBBGGRR.
0
 
dssisupportAuthor Commented:
This is what I needed actually but you pointed me in the right direction. Thanks.

function toVBColor(r,g,b) {
   return (256 * 256 * b)   + g * 256 + r;
0
 
GwynforWebCommented:
TY.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.