Results 1 to 11 of 11

Thread: Color values

  1. #1
    antma
    Guest

    Color values

    Hi there

    Is there a way that the rgb color values be returned and places withing a rgb() statement?

    thanx

  2. #2
    antma
    Guest
    Returned form a color dialog box?

  3. #3
    Registered User Olly's Avatar
    Join Date
    Apr 2001
    Location
    Switzerland
    Posts
    252
    you mean the rgb values out of the standard returned color numbers?
    Standrad would be like

    commondialog1.showcolor
    color = commondialog1.color

  4. #4
    antma
    Guest
    yes
    kinda like say Rgb(X,Y,Z) if a rnd color is click on the dialogbox

  5. #5
    Registered User Olly's Avatar
    Join Date
    Apr 2001
    Location
    Switzerland
    Posts
    252
    code to convert a long into rgb:

    Code:
    Private Sub Command1_Click()
        R = Val(InputBox$("Red Value"))
        B = Val(InputBox$("Blue Value"))
        G = Val(InputBox$("Green Value"))
        Lng$ = B * 65536 + G * 256 + R
        MsgBox Lng$
    End Sub
    Last edited by Olly; Jun 8th, 2001 at 05:12 PM.

  6. #6
    Registered User Olly's Avatar
    Join Date
    Apr 2001
    Location
    Switzerland
    Posts
    252

    I got it! :)

    Add this function to a Module:

    Code:
    Option Explicit
    Public Function gfnLongToRGBString(lColor As Long) As String
       iRed = lColor Mod 256
       iGreen = ((lColor And &HFF00) / 256&) Mod 256&
       iBlue = (lColor And &HFF0000) / 65536
       gfnLongToRGBString = Str$(iRed) & Str$(iGreen) & Str$(iBlue)
    End Function
    To use this code add the following lines to a form:

    Code:
    Command1_Click()
       Dim RGBVal as String
       RGBVal = gfnLongToRGBString(SYSCol)
    End Sub
    SYSCol is the system color (Long value) like &H0 (Black). RGBVal will be set to "000000" (Black)

  7. #7
    antma
    Guest
    Another question

    I dont know if u can help me on this one

    I'm trying to use that values within a scroll bar
    Now what im doing is once the user has clicked the color option the text of a richedit contol changes...

    Im using a scroll bar to change the color of the text by scrolling with it ...
    when the user goes back the same text color must be shown that showed previously

    any ideas??

  8. #8
    Registered User Olly's Avatar
    Join Date
    Apr 2001
    Location
    Switzerland
    Posts
    252

    Thumbs up

    Code:
    Private Sub VScroll1_Change(index As Integer)
        RichTextBox1.SelColor = RGB(VScroll1(0).Value, VScroll1(1).Value, VScroll1(2).Value)
    End Sub
    {but your rtf box will lose its focus so better use the CommonDialog or some Coler listbox from vbaccelerator.com}
    oh no, it works, it's all fine just thought for a moment
    Last edited by Olly; Jun 8th, 2001 at 05:30 PM.

  9. #9
    antma
    Guest
    Thanx a million!!

  10. #10
    Registered User Olly's Avatar
    Join Date
    Apr 2001
    Location
    Switzerland
    Posts
    252
    no prob

  11. #11
    Megatron
    Guest
    Originally posted by Olly
    code to convert a long into rgb:

    Code:
    Private Sub Command1_Click()
        R = Val(InputBox$("Red Value"))
        B = Val(InputBox$("Blue Value"))
        G = Val(InputBox$("Green Value"))
        Lng$ = B * 65536 + G * 256 + R
        MsgBox Lng$
    End Sub
    You can use the RGB() function too.

    lColor = RGB(R, G, B)

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