Results 1 to 5 of 5

Thread: Converting RGB() to R G and B Values

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 1999
    Location
    NY
    Posts
    45

    Post

    The tip doesn't work:
    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


    It overflows on G and B value, but R works right, i need a working one :-) It's supposed to convert an RGB value (such as the RGB function) into the specified part (R G or B).

    ------------------
    -Mystiq

    [This message has been edited by mystiq (edited 11-27-1999).]

    [This message has been edited by mystiq (edited 11-27-1999).]

  2. #2
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    ma,usa
    Posts
    485

    Post

    Please tell me what this is supposed to do before I try to answer. Is it supposed to return the value of a color selected,covert colors coded in other formats, or something different? I want to try to help.

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 1999
    Location
    NY
    Posts
    45

    Post

    In other words: unRGB(RGB(255,128,64),1) should return 128, because 1 is green, and the green value is 128. But the function doesn't work, it'll overflow, only red works.

    ------------------
    -Mystiq

  4. #4
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,176

    Post

    Try this instead:
    Code:
    Public Function UnRGB(ByVal RGBCol As Long, ByVal Part As Integer) As Integer
        UnRGB = Val("&H" & Mid$(Right$("000000" & Hex(RGBCol), 6), 5 - (2 * Part), 2))
    End Function
    ------------------
    Aaron Young
    Analyst Programmer
    aarony@redwingsoftware.com
    adyoung@win.bright.net

  5. #5

    Thread Starter
    Member
    Join Date
    Feb 1999
    Location
    NY
    Posts
    45

    Post

    Yay, that works, thanks

    ------------------
    -Mystiq

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width