• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 804
  • Last Modified:

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.
0
dssisupport
Asked:
dssisupport
  • 2
  • 2
1 Solution
 
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now