Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Bug in RGB() function
Message
From
26/06/2015 03:03:53
 
 
To
26/06/2015 01:04:44
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01621469
Message ID:
01621474
Views:
91
>Either I am missing something or there is a significant bug in the RGB function.
>
>The value of RGB((204,198,149) is returned as 9815756. In hex this is #95C6CC.
>
>That is completely wrong. The value of RGB(204,198,149) is 13420181. In hex that is #CCC695.
>
>I finally figured out the problem: any time the first number was > 99, the RGB() function is returning the number of the RGB in _opposite_ order! IOW the value of RGB(204,198,149) should be 13420181, yet VFP returns 9815756. However doing the RGB backwards, as in RGB(149,198,204) results in the correct decimal for the original order: 13420181.
>
>VFP is reversing the parameters, seemingly randomly, but I ran that RGB on 3 different PC's and it always came up the same wrong answer.
>
>Anybody know anything about this?
>
>TIA

It might be that the RGB() function is not doing what you expect: http://fox.wikis.com/wc.dll?Wiki~VFPFunctionRGB~Wiki

The RGB() function and its inverse RGBCOMP() (in FoxTools.FLL) are consistent:
SET LIBRARY TO ( HOME( ) + "FoxTools.FLL" ) && for RGBCOMP() function, see FoxTools.CHM help

CREATE CURSOR TestResults ;
	( RedVal I ;
	, GreenVal I ;
	, BlueVal I ;
	, RedValOK L ;
	, GreenValOK L ;
	, BlueValOK L )

LOCAL ;
	lnRedTest ;
	, lnGreenTest ;
	, lnBlueTest ;
	, lnRedResult ;
	, lnGreenResult ;
	, lnBlueResult

FOR m.lnRedTest = 0 TO 255 STEP 1
	FOR m.lnGreenTest = 0 TO 255 STEP 1
		FOR m.lnBlueTest = 0 TO 255 STEP 1
			=RGBCOMP( RGB( m.lnRedTest, m.lnGreenTest, m.lnBlueTest ), @m.lnRedResult, @m.lnGreenResult, @m.lnBlueResult )
			
			INSERT INTO TestResults ;
				( RedVal ;
				, GreenVal ;
				, BlueVal ;
				, RedValOK ;
				, GreenValOK ;
				, BlueValOK ) ;
				VALUES ;
					( m.lnRedTest ;
					, m.lnGreenTest ;
					, m.lnBlueTest ;
					, ( m.lnRedTest = m.lnRedResult ) ;
					, ( m.lnGreenTest = m.lnGreenResult ) ;
					, ( m.lnBlueTest = m.lnBlueResult ) )
		
		ENDFOR
	
	ENDFOR

ENDFOR

SELECT ;
	* ;
	FROM TestResults A ;
	WHERE NOT A.RedValOK ;
		OR NOT A.GreenValOK ;
		OR NOT A.BlueValOK ;
	INTO CURSOR RGBFuncBugs ;
	ORDER BY A.RedVal, A.GreenVal, A.BlueVal

* Zero rows returned in RGBFuncBugs cursor
Interesting side note - on my system, all of the above code, including the SELECT at the end, runs in just about exactly one minute. It's generating a little over 16M rows in the TestResults cursor in that time, or more than 250,000 rows per second !
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform