How to get BackColor as string like "255,255,255"? 
Author Message
 How to get BackColor as string like "255,255,255"?

Hi all:

I am new to the VB and please help me.

In my program, I want to know any way to get the value of
BackColor of a control
as a string like "255,155,55"

I get the BackColor but which is a number likes 4300270
and this is not what I want.

Thanks in advance

Dennis Chen



Fri, 17 Nov 2000 03:00:00 GMT  
 How to get BackColor as string like "255,255,255"?

To translate a Long color value Colr to r, g, b components, use

  R = Colr Mod 256
  Colr = Colr \ 256
  G = Colr Mod 256
  Colr = Colr \ 256
  B = Colr Mod 256

Watch out, though!  System colors such as vbButtonFace are special codes
(their value is less than zero).  To translate these to Long color values,
you must use the GetSysColor() API function.

Jim Deutch
MS Dev MVP



Quote:
> Hi all:

> I am new to the VB and please help me.

> In my program, I want to know any way to get the value of
> BackColor of a control
> as a string like "255,155,55"

> I get the BackColor but which is a number likes 4300270
> and this is not what I want.

> Thanks in advance

> Dennis Chen



Sat, 18 Nov 2000 03:00:00 GMT  
 How to get BackColor as string like "255,255,255"?

Hi Dennis,

Here is a example of function to do what you need.

-----------------------------------------------------

Public Function LongToRGB(lColor As Long) As String

    Dim lBlue As Long, lGreen As Long, lRed As Long

    'blue
    If lColor > 65535 Then
        lBlue = lColor \ 65536
        lColor = lColor - (65536 * lBlue)
    End If

    'green
    If lColor > 255 Then
        lGreen = lColor \ 256
        lColor = lColor - (256 * lGreen)
    End If

    'red
    lRed = lColor

    LongToRGB = lRed & "," & lGreen & "," & lBlue

End Function

-------------------------------------------------------------

You call it like LongToRGB(4300270), and it will return
the string "255,155,55" ...

Chiao...

Quote:

> Hi all:

> I am new to the VB and please help me.

> In my program, I want to know any way to get the value of
> BackColor of a control
> as a string like "255,155,55"

> I get the BackColor but which is a number likes 4300270
> and this is not what I want.

> Thanks in advance

> Dennis Chen

---------------------------------------
Eric Beaumier
System Analyst
Bell Sygma (BSTS)
BESI (div. Application)
Phone : (514) 786-0481

---------------------------------------


Sat, 18 Nov 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Winsock INET_ADDR returns INADDR_NONE for 255.255.255.255

2. Vertical Scrool Bar Does not appear when sized to 255 x 255

3. SQL Strings appear to truncate to 255 characters

4. Help! DoCmd.ApplyFilter cuts String after 255 characters

5. Strings longer than 255 characters into word field using vb6

6. Word Query String more than 255 char

7. Populating Bookmarks with strings of > 255 characters

8. whats the best way to parse a string and return 255 characters chunks

9. Strings > 255 from Memo fields

10. string * 255?

11. Label-Object containing strings greater than 255 chars

12. String field got trimmed to 255 characters

 

 
Powered by phpBB® Forum Software