Hex or RGB ?

I have noticed that some Xojo code segments use RGB values, and yet others use Hexadecimal triplet codes.
Is there any advantage of using one over the other, or is it simply down to personal preference?

In other words, are there any circumstances where one type of colour code must be used, or can either type of colour code always be used?
Also, if one type of colour code can be used anywhere / everywhere - is there any reason to use one type over the other?

Thank you.

Example 1 using RGB:

if row mod 2 <> 0 then
end if

g.FillRect 0,0,g.width,g.height[/code]

Example 2 using Hex Codes:

// SET THE SELECTED ROW COLOUR If Me.Selected(row) Then g.ForeColor = &cADC4E1 g.FillRect (0, 0, g.Width, g.Height) Return True End If

I much prefer RGB as I find it very easy to program with the RGB method.

I think it is probably a simple case of personal preference.

I use RGB

It’s personal preference, except where you want to use a variable for one or more RGB values.

c = rgb(x, y, z)

I use hex codes.

I could be mistaken but I thought RGB was a function whereas &cRRGGBBAA is a literal.

Thank you everyone.

Benchmark shows about a 20% time savings using the literal vs RGB function. Both are fast enough to not be a concern generally… I had to do a loop of 10 million iterations to see a measurable difference.

apart from the performance differences, I’m using more and more the Hex format, once I discovered the possibility to quickly insert the hex code, by right clicking the contextual popup menu anywhere inside the code window.

I generally use the literal when the value is fixed and the RGB function when it is variable – obviously one has to use RGB (or HSV etc.) when the value is variable.

The compiler could probably be optimized to replace the function with the literal when the values are fixed. Maybe with LLVM if not now.

I think there has been a feature request to calculate some things at compile time. e.g. chr(65) or asc(“A”). Or math functions like sqrt. But current compiler may not do that.

I use the hex one if I have color as hex (E.g. copied from html). If I have it as decimal numbers, I use RGB.