Save color to sqlite table

Hi. I’m wanting to save some colors to a sqlite table. I’ve read that sqlite does not have a field for color and that you have to convert it to a variant first then to a string. Here’s what’s happening. I have a listbox with several color schemes. Select one, and it populates 5 myColor properties. I take these properties, convert to a variant, then convert to string, then save to the table. When I save this one for instance: &cff4d4d, the table shows it as this: &h00FF4D4D

Is the “h00” equivalent to the “c”? Or is something wrong here?

I’ve been working all day, and I might just need a fresh start tomorrow but wanted to see if I am on the right path and may just be missing something simple

Here’s my code:

[code]'update user table
dim tC1, tC2, tC3, tC4, tC5 as String
dim v1, v2, v3, v4, v5 as Variant

'first convert color to variant
v1 = myColor1
v2 = myColor2
v3 = myColor3
v4 = myColor4
v5 = myColor5

'then convert variant to string
tc1 = v1
tc2 = v2
tc3 = v3
tc4 = v4
tc5 = v5

'then save to table
dim sql as String = “SELECT * FROM CustColors”
dim rs as RecordSet = dbUser.SQLSelect(sql)

if rs.RecordCount > 0 then
rs.Edit

rs.Field(“Color1”).StringValue = tc1
rs.Field(“Color2”).StringValue = tc2
rs.Field(“Color3”).StringValue = tc3
rs.Field(“Color4”).StringValue = tc4
rs.Field(“Color5”).StringValue = tc5

rs.Update

dbUser.Commit
else
dim dr as new DatabaseRecord
dr.Column(“Color1”) = tc1
dr.Column(“Color2”) = tc2
dr.Column(“Color3”) = tc3
dr.Column(“Color4”) = tc4
dr.Column(“Color5”) = tc5
dbUser.InsertRecord “CustColors”, dr
dbUser.Commit
end if[/code]

my opinon? do not use variants.

dim c as color=color.red // Original Input Color
dim h as string=str(c) // convert that color to a string, store the STRING in database
dim c1 as color=rgb(val("&H"+mid(h,6,2)),val("&H"+mid(h,8,2)),val("&H"+mid(h,10,2))) // convert string back to a color

[quote=381945:@Ryan Hartz]Hi. I’m wanting to save some colors to a sqlite table. I’ve read that sqlite does not have a field for color and that you have to convert it to a variant first then to a string. Here’s what’s happening. I have a listbox with several color schemes. Select one, and it populates 5 myColor properties. I take these properties, convert to a variant, then convert to string, then save to the table. When I save this one for instance: &cff4d4d, the table shows it as this: &h00FF4D4D

Is the “h00” equivalent to the “c”? Or is something wrong here?

I’ve been working all day, and I might just need a fresh start tomorrow but wanted to see if I am on the right path and may just be missing something simple

Here’s my code:

[code]'update user table
dim tC1, tC2, tC3, tC4, tC5 as String
dim v1, v2, v3, v4, v5 as Variant

'first convert color to variant
v1 = myColor1
v2 = myColor2
v3 = myColor3
v4 = myColor4
v5 = myColor5

'then convert variant to string
tc1 = v1
tc2 = v2
tc3 = v3
tc4 = v4
tc5 = v5

'then save to table
dim sql as String = “SELECT * FROM CustColors”
dim rs as RecordSet = dbUser.SQLSelect(sql)

if rs.RecordCount > 0 then
rs.Edit

rs.Field(“Color1”).StringValue = tc1
rs.Field(“Color2”).StringValue = tc2
rs.Field(“Color3”).StringValue = tc3
rs.Field(“Color4”).StringValue = tc4
rs.Field(“Color5”).StringValue = tc5

rs.Update

dbUser.Commit
else
dim dr as new DatabaseRecord
dr.Column(“Color1”) = tc1
dr.Column(“Color2”) = tc2
dr.Column(“Color3”) = tc3
dr.Column(“Color4”) = tc4
dr.Column(“Color5”) = tc5
dbUser.InsertRecord “CustColors”, dr
dbUser.Commit
end if[/code][/quote]
What you’re missing is the fourth bit of data on a color… Alpha. On a color literal, the data is on the right. On a hex value, they’re on the left.

For example a translucent red color might look like this:

&cFF000077

Whereas the same value in hex is

&h77FF0000

Thank you both for the help. Greg - the alpha piece did the trick for me. Thanks!

Color can be cast to an integer and saved as such:

dim c as color = &cFFFFFFFF dim i as integer = Integer(c) dim c1 as color = Color(i)