Color RGB from a Long Using “Point” method

By | 2002-06-01

After using the POINT method the computer returns a long value like 16711680 but with this function it will return the color in the RGB(R,G,B)
format.

Original Author: Brandon Brownlee

Assumptions

Start a new project and make any picture you have the background for your form.
Then start it and move the mouse on the form and look at the caption of the form.

Returns

Returns Rgb(R,G,B) format from a Long Value

Code

Public Blue As Double
Public Green As Double
Public Red As Double
Public BlueS As Double
Public GreenS As Double
Public RGBs As String
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, _
Y As Single)
Call ConvertRGB(Form1.Point(X, Y))
Form1.Caption = RGBs
End Sub
Public Function ConvertRGB(P)
  Blue = Fix((P / 256) / 256)
  BlueS = (Blue * 256) * 256
  Green = Fix((P - BlueS) / 256)
  GreenS = Green * 256
  Red = Fix(P - BlueS - GreenS)
  RGBs = "RGB(" & Red & ", " & Green & ", " & Blue & ")"
End Function

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.