Translate Color Values

With the RGB function, VB provides a neat and valuable tool for converting separate Red, Green, and Blue values into a single Long color value.. However, VB won’t let you translate back from its this color value to back to its constituent RGB values. But, you can pick the individual colors out of a hexadecimal representation of the Long value produced by RGB. The colors fall in “BBGGRR” order. Put this code in a module:

 Type RGB_Type	R As Long	G As Long	B As LongEnd TypeFunction ToRGB(ByVal Color As Long) As RGB_Type	Dim ColorStr As String	ColorStr = Right$("000000" & Hex$(Color), 6)	With ToRGB	.R = Val("&h" & Right$(ColorStr, 2))	.G = Val("&h" & Mid$(ColorStr, 3, 2))	.B = Val("&h" & Left$(ColorStr, 2))	End WithEnd Function

To use this function, put a picture in a form’s Picture property, and insert this code in that form:

 Private Sub Form_MouseUp(Button As Integer, Shift _	As Integer, X As Single, Y As Single)	Dim RGB_Point As RGB_Type	RGB_Point = ToRGB(Point(X, Y))	Caption = RGB_Point.R & " " & RGB_Point.G & " " & _		RGB_Point.BEnd Sub

Click on different places on the picture. VB3 users must return the values differently, because VB didn’t support the return of a user-defined type until VB4.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS

homes in the real estate industry

Exploring the Latest Tech Trends Impacting the Real Estate Industry

The real estate industry is changing thanks to the newest technological advancements. These new developments — from blockchain and AI to virtual reality and 3D printing — are poised to change how we buy and sell homes. Real estate brokers, buyers, sellers, wholesale real estate professionals, fix and flippers, and beyond may