Exporting a ListBox into html

I got the need to export a ListBox contents into a html document and so I wrote a Method to do that.

The result is nice even if the columns withs have troubles because of the differences in the used Fonts (System in Xojo, Times ? in html).

Then, two days after and a travel to the local hospital, I wanted to add a user selected background colors (header / rows).

At html write time, I decided to use Hex to write the color:

Color_Fldr = "#" + Hex(List_Color_Folder.Red) + Hex(List_Color_Folder.Green) + Hex(List_Color_Folder.Blue)

And of course, as the docs says, I get <tr bgcolor=#07F0> instead of <tr bgcolor=#007F00>

The result was a nice green - I do not know if this was what I was asking :wink:

I checked in the documentation, and even the API2 have the same behavior (and they show a workaround).

My bad: I will use RGB instead, but how many wasted time ?

BTW: I checked (because I am curious) as eager to know I am, in the Web part, and WebHex does not exists (I typed WebHex: try it for a grin).

When the code start to be unreadable, my mouth start to be like The Clown (from Batman): usually, this kind of code start to be glibberish to my eye after some hours :frowning:

For those who knows: is Hex working the same in other developement environments ?

The new code is:

  Color_Head = "style=""background-color:rgb(" + Str(Table_Header_Bkgnd_Color.Red) + Str(Table_Header_Bkgnd_Color.Green) + Str(Table_Header_Bkgnd_Color.Blue) + """)"

Each newly written feature needs new stuff (often searches)… at some point in the future, I will start to ask myself why I continue (to code, to embellish my applications, to use a computer, to…).

This is sad.

Use this function to get the right hex color:

Function ToHex(Extends value As Color, hasPrefix As Boolean = False) As String
  Var arcHexColors() As String

  ' Check for prefix.
  If hasPrefix Then ' Add prefix.
    arcHexColors.Add("#")
  End If

  ' Add color.
  arcHexColors.Add(value.ToString.Right(6))
  
  ' Compose hex color.
  Return String.FromArray(arcHexColors, "")
End Function
function HEX16(x as integer) as string
return right("00"+hex(x),2)
end function

use instead of just “hex”

I think, maybe, the main point Emile is making is that you can’t “assume” that any given Xojo function works the way you expect. My response is, that’s correct - you have to read the documentation and base your programming on that, not what you expect. And in this case, the current documentation gives an example of formatting the output as Emile was expecting (just like Dave’s example).

So, yes, I’ve learned to always read (or at least scan) the entire documentation entry on any given function or feature, as I’ve been bitten by issues like this many times before.

Of course, all of this is predicated on the documentation being correct, which is not always the case either.

Thank you all for your answers.

Jay, you are right. I only have to add…

I forgot what you wrote because I’ve made a pause in using Xojo.

Now, I used RGB (as I noted earlier) and this is good.

The advices are good too.

I wanted to add… I had a non responding UI: the Canvas I used to display the ListBox background colors were… not colorized, some minutes after I sent this conversation.

After some hours, I was curious… too curious to know why, and so I fired the project and checked:

I add Invalidate, a System.DebugLog, etc.

At last, I realized that I set the correct ForeColor in Canvas1.Paint, but I forgot to fill the Canvas !!!

Yes, Emile, you are starting to be an oldster.

What wrote the us people ?

You forgot to drink your coffee ?
You forgot to prepare your coffee ?
You forgot to add sugar in your coffee ?

Yes, you’re old !

(It have long ears, it ears carrots, it skip: it’s a rabbit !) or something like that ! :wink:

Have a nice Sunday all…

Did I told you that there were a bunch of very nice women at the hospital ?
(No, Emile, you’re too old for that too :frowning: )

I made aversion of Hex that takes the various sized integers and gives you back a hex representation that is that many bits
If you pass in a Uint8/Int8 you get a 2 digit hex value (8 bits) etc
If you pass in a Uint16 (or int16) you get a 4 digit hex value (16 bits) etc

Thank you Norman.