Microsoft KB Archive/216379

= FIX: Visual Basic 6.0 Booleans are Coerced to Localized Strings =

Article ID: 216379

Article Last Modified on 5/13/2003

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q216379



SYMPTOMS
When Boolean constants or variables are concatenated into a string and the Regional Setting is not English, Visual Basic 6.0 coerces the Boolean value to a string containing the text of the value. For example, when the Regional Settings are set to French, you would see the string "Vrai" for True. Unfortunately, "Vrai" will not be converted back to the Boolean True even when CBool is applied. If CBool is applied to the string containing the localized word, a Type Mismatch error occurs.



RESOLUTION
The simplest work around is to apply CStr or Str$ to the Boolean constant or variable before it is coerced into the localized word. For example, in the following sample, the Boolean value True is explicitly converted to a string to retain the English value. The string can then be successfully parsed and converted back to a Boolean value.

sTemp = "-" & CStr(True) ' CStr keeps the English word True. Debug.Print sTemp sTemp = Right(sTemp, 4) Debug.Print sTemp bTemp = CBool(sTemp)    ' No Type Mismatch error.



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

This bug was corrected in Visual Studio 6.0 Service Pack 3. For more information about Visual Studio service packs, please see the following articles in the Microsoft Knowledge Base:

194022 INFO: Visual Studio 6.0 Service Packs, What, Where, Why

194295 HOWTO: Tell That Visual Studio 6.0 Service Packs Are Installed



MORE INFORMATION
Visual Basic 6.0 coerces Boolean constants and variables to strings containing localized words when Regional Settings are set to a language other than English. Visual Basic 6.0 is unable to convert these localized strings back to their Boolean values.

Steps to Reproduce Behavior
 Click the Start button, point to Settings and then select Control Panel. In the Control Panel dialog box, double-click Regional Settings. In the Regional Settings dialog box, click the Regional Settings tab (General tab on Windows 2000), set the language to French, then click OK. You need to reboot your computer if you are using the Windows 95 or Windows 98 operating system. Create a Visual Basic 6.0 Standard EXE project. Form1 is created by default.  Paste the following code in the General Declarations section of Form1: Private Sub Form_Load sTemp = "-" & True  ' Visual Basic 6.0 coerces True to localized string Debug.Print sTemp sTemp = Right(sTemp, 4) Debug.Print sTemp bTemp = CBool(sTemp) ' Visual Basic 6.0 Type Mismatch error occurs here. End Sub  Step through the code and monitor the value of sTemp. You can do this by pressing F8 repeatedly and watch the values displayed for sTemp in the Immediate Window or you can place the mouse pointer over the variable in the integrated development environment (IDE). After the first line is executed, sTemp is coerced or translated into -Vrai. Next, the hyphen is parsed out. When the conversion to Boolean is attempted, a Type Mismatch error occurs.</li></ol>

Additional query words: False

Keywords: kbbug kbfix kbintl kbintldev kbvs600sp3fix KB216379

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.