Reg Exp
Web Design
Notes Client
Using Color Fields
The Notes Designer help on color fields is a little confusing. It's talking about having your column formula go against a profile and all kinds of confusing items. That's the way it was described because that's the way the mail template uses color fields. But let's say you have an application and you want different documents to show up with different foreground and background colors in the views, but you want these values to be controlled by an administrator. It's an application used by many people, but the color control only comes from a few people. Do you have to do this the way the profile talks about?

Of course not (this tip would be pretty useless otherwise). Personally, I think the easiest way to implement color fields (ones to be used in views) is to set a field on the documents shown in the views. The field is a multi-valued number field. There are either 3 or 6 numbers. If there are only 3 numbers, then the foreground color is being set. If there are 6 numbers, then both the foreground and background colors are being set. Each group of three numbers is the RGB value. So, for example, if the three numbers are 255 : 255 : 0 then the foreground color will be yellow. With 6 numbers, the background color is the first (I don't know why) group of three, and the foreground color is the second group of three.

The color column can (and should) be a hidden column in your view. All columns up until another color column will take on the colors defined by the column. You can have as many color columns as you want. One good thing to do is to have a color column that has no content - it's just an indicator (background color of red, yellow, or green, for example) and then the next column is a hidden color column that sets the foreground color back to black.

Let's get back to the task at hand: having colors that are set by the administrators. You can use a color field in a document for your administrators to work with. Color fields provide the user with a color picker. They can pick from the standard Notes pallette, or use the web pallette (if their user settings state to use the web pallette), or they can specify an exact RGB value. The color fields are pretty easy to work with from an end user standpoint.

From a design standpoint, the value is an 8 character string. The first two characters are irrelevant (from what I've seen). The next two are the red value, in hex. The next two are the green value, in hex. And the last two characters are the blue value, again in hex. The numbers used in the column are in decimal, though, so you need to be able to convert from one to the other. It's actually pretty simple using LotusScript to convert from hex to decimal. "&H" is an indicator that the number is hex, so Cint("&H" & value) (where value is the string) will convert value from hex to decimal. Taking your 8 character string, here is code that will give you the integer values:

Sub GetRGB(rgb As String, r As Integer, g As Integer, b As Integer)
   r = 0
   g = 0
   b = 0
   If Len(rgb) <> 8 Then Exit Sub
   r = Cint("&H" & Right(Left(rgb, 4), 2))
   g = Cint("&H" & Right(Left(rgb, 6), 2))
   b = Cint("&H" & Right(rgb, 2))
End Sub

Now, in your administration form, you could set the red, green, and blue values as numbers in existing documents and set them in a hidden field somewhere for new documents to look up. Now, your application can have customized colors for different documents and those colors can be set by administrators. You could even take this technique and allow each individual document to have its own color in the view (wow, could that be a mess). But each document could have its color set and the value stored in a field that is used by the view.