Microsoft KB Archive/193728

= PRB: SET COLLATE TO Command Causes Inconsistent Comparisons =

Article ID: 193728

Article Last Modified on 2/11/2005

-

APPLIES TO


 * Microsoft Visual FoxPro 5.0 Standard Edition
 * Microsoft Visual FoxPro 5.0a
 * Microsoft Visual FoxPro 6.0 Professional Edition

-



This article was previously published under Q193728



SYMPTOMS
Comparing the equality of alphabetic characters using the UPPER and LOWER functions with the collation sequence set to Czech or Hungarian, produces incorrect results with some or all of the comparisons.



RESOLUTION
One workaround is to use the double equal operator (==) when making string comparisons.



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.



MORE INFORMATION
Codepage 1250 or 852 works for a collation sequence of either Hungarian or Czech.

Steps to Reproduce Behavior
 In the Config.fpw file, set the codepage to 1250 as follows and restart Visual FoxPro:

Codepage=1250

  Create a program containing the following code and run the program. This code compares the lower case letters of the alphabet:

MODIFY WINDOW SCREEN FONT "Courier New",10 CLEAR *SET COLLATE TO "MACHINE" SET COLLATE TO "CZECH" && or "Hungary" with codepage of 1250 ? space(2)+"Lower to Upper"+space(14)+"Upper to Lower"+space(13) ; +"ASC Values"

? space(2)+REPLICATE("-",14)+space(14)+REPLICATE("-",14)+space(13); +REPLICATE("-",12) FOR i = 1 TO 26 DO test WITH CHR(96 + i)  ENDFOR

PROCEDURE test (s)

? s, "Lower("+s+") to Upper("+s+"):", LOWER(s) = UPPER(s), ; " Upper("+s+") to Lower("+s+"):", UPPER(s) = LOWER(s),; ASC(s), "=", ASC(UPPER(s)), "?"

Comparisons using lower case letters always produce incorrect results when comparing values returned from the LOWER to the UPPER functions (? LOWER(s)=UPPER(s)). All of the UPPER to LOWER comparisons with lower case letters (? UPPER(s)=LOWER(s)) are incorrect except for the following letters:

 Letter  Decimal

b       98 f       102 g       103 h       104 j       106 k       107 m       109 p       112 q       113 v       118 w       119 x       120 NOTE: The lower case "g" evaluates incorrectly when comparing UPPER to LOWER under the Hungary collation sequence.   Create another program and add the following code to compare the upper case letters of the alphabet:

MODIFY WINDOW SCREEN FONT "Courier New",10 CLEAR *SET COLLATE TO "MACHINE" SET COLLATE TO "CZECH" && or "Hungary" with codepage of 1250 ? space(2)+"Lower to Upper"+space(14)+"Upper to ;    Lower"+space(13)+"ASC Values"

? space(2)+REPLICATE("-",14)+space(14)+REPLICATE("-",14)+space(13); +REPLICATE("-",12) FOR i = 1 TO 26 DO test WITH CHR(64 + i)  ENDFOR

PROCEDURE test (s)

? s, "Lower("+s+") to Upper("+s+"):", LOWER(s) = UPPER(s), ; " Upper("+s+") to Lower("+s+"):", UPPER(s) = LOWER(s),; ASC(s), "=", ASC(UPPER(s)), "?"

Comparisons using upper case letters always produce incorrect results when comparing values returned from the LOWER to the UPPER functions (? LOWER(S)=UPPER(S)). All of the UPPER to LOWER comparisons with upper case letters (? UPPER(S)=LOWER(S)) are incorrect except for the following letters:

 Letter  Decimal

B       66 F       70 G       71 H       72 J       74 K       75 M       77 P       80 Q       81 V       86 W       87 X       88

NOTE: The upper case "G" evaluates incorrectly when comparing UPPER to LOWER under the Hungary collation sequence.  Remove the CodePage= command from the Config.sys and change the SET COLLATE TO command to MACHINE. Now all the comparisons between UPPER and LOWER and LOWER and UPPER values are correct.</ol>

<div class="references_section">