dim I as long
dim R as byte,G as byte,B as byte
dim cR as byte,cG as byte,cB as byte
dim Idx as long,D as long
dim tD as long
cR=C and &HFF
cG=(C and &HFF00&)\&H100&
cB=(C and &HFF0000)\&H10000
D=&HFFFFFF '足够大的数字
for i=0 to 255
R=ColorTable(i) and &HFF
G=(ColorTable(i) and &HFF00&)\&H100&
B=(ColorTable(i) and &HFF0000)\&H10000
tD=abs(R-cR)^2+abs(G-cG)^2+abs(B-cB)^2
if tD<D then
Idx=I
D=tD
If D=0 then exit for
End If
next i