Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
RGB() to web colors
Message
De
31/08/2001 06:46:35
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00551143
Message ID:
00551284
Vues:
23
>A little while ago, there was a thread regarding converting the VFP RGB() color to a hex(?) number for display on a web page. Does anybody remember the solution? Basically, I want
RGB( 250, 238, 209 )
as my background color. Thanks.
>John

John,
Basically it's just putting R,G,B side by side.
function RGB2cWebColor
lparameters tnRed, tnGreen, tnBlue
return right(trans(tnRed,  '@0'),2)+;
       right(trans(tnGreen,'@0'),2)+;
       right(trans(tnBlue, '@0'),2)
* or alternatively you can swap red an blue
return right(trans(rgb(tnBlue,tnGreen,tnRed),'@0'),6)
Below function makes conversion from either rgb(r,g,b) or r,g,b passed as parameters (note uses alternative swapping) :
function Color2Web
lparameters tnRed, tnGreen, tnBlue
if type('tnRed')='N' and ;
	type('tnGreen')='N' and ;
	type('tnBlue')='N'    && Passed as separate r,g,b
	return right(transform(rgb(tnBlue,tnGreen,tnRed),'@0'),6)
endif
if type('tnRed')='N' && passed as rgb(r,g,b)
	tnBlue  = int(tnRed/256^2)%256
	tnGreen = int(tnRed/256^1)%256
	tnRed   = int(tnRed/256^0)%256
	return Color2Web(tnRed, tnGreen, tnBlue)
endif
return 'FFFFFF' && Otherwise return default white
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform