14 November 2009

Snip: Random colours

image

I spent most of the day capturing all our fuel slips since we bought our current car (Dec 2007) and then decided to learn about fuel consumption and everything that goes with it. I employed FushionCharts Free again, but found the charts a little dull if I didn’t specify the colour codes.

I remember recently looking for a way to randomise the colour codes, as I pull all my information from an SQL database dynamically, but I didn’t find a workable solution then, and tonight proved pretty fruitless as well. Then I realised that all I needed was a random hex code generator. Or a way to convert random numbers to hex.

I finally pieced bits together, and this is what it looks like:

Function RandomCode(iLength)

Dim max,min
max=100
min=1
Randomize
iCode = ((Int((max-min+1)*Rnd+min))*1677215)
RandomCode = Left(Hex(iCode), 6)

End Function



I am rather pleased with the results. Even the line graphs look different with every refresh.



So, this is our fuel consumption for the month to date.



image



And for the year to date:



image



Still trying to figure out how to work out how much CO2 we pump into the atmosphere, but I was pretty pleased to discover that our average MPG over the entire period is 33, which I believe is pretty good.

1 comment:

Wenchy said...

You made me smile... to have taken time to write a bit of random code on a Saturday afternoon.

:)

Related Posts with Thumbnails