You receive a "Constant vbFromUnicode was not upgraded" message in Upgrade Report after you upgrade a Visual Basic 6.0 project to Visual Basic .NET or Visual Basic 2005 (311338)



The information in this article applies to:

  • Microsoft Visual Basic 2005 Express Edition
  • Microsoft Visual Basic .NET (2003)
  • Microsoft Visual Basic .NET (2002)

This article was previously published under Q311338

SYMPTOMS

When you upgrade an application that converts Unicode strings to an American National Standards Institute (ANSI) byte array by using the StrConv function and the vbFromUnicode constant from Microsoft Visual Basic 6.0 to Visual Basic .NET or Visual Basic 2005, the following UPGRADE comments appear in the Task List of the upgrade report for the Visual Basic .NET or Visual Basic 2005 project:

'UPGRADE_ISSUE: Constant vbFromUnicode was not upgraded.
'UPGRADE_TODO: Code was upgraded to use System.Text.UnicodeEncoding.Unicode.GetBytes() 
which may not have the same behavior.
Bytes = System.Text.UnicodeEncoding.Unicode.GetBytes(StrConv(SomeString, vbFromUnicode))
					

CAUSE

Although Visual Basic .NET and Visual Basic 2005 support the StrConv function, Visual Basic .NET and Visual Basic 2005 do not support the vbFromUnicode constant.

RESOLUTION

To resolve this problem, use the Encoding object in the System.Text namespace to convert this application. You must change the code in the Visual Basic .NET project as follows:
Bytes = System.Text.Encoding.GetEncoding(1252).GetBytes(SomeString)
				
The value 1252 in the parentheses represents the code page to be used in the conversion. Code page 1252 includes characters for Western European languages, including US English. You can also user other code pages. For example, you can also use 1253 for Greek character conversion, or you can use 1251 for Cyrillic conversion.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Create a Visual Basic 6.0 project that contains the following code:
    ' Convert String data to ANSI byte array.
       Bytes = StrConv(SomeString, vbFromUnicode)
    					
  2. Start Microsoft Visual Studio .NET or Visual Studio 2005.
  3. Open the Visual Basic 6.0 project in Visual Studio .NET or in Visual Studio 2005. Notice that the Upgrade Wizard migrates the code in step 1 as follows:
    Bytes = System.Text.UnicodeEncoding.Unicode.GetBytes(StrConv(SomeString, vbFromUnicode))
    					

REFERENCES

For more information about how to migrate Visual Basic 6.0 projects to Visual Basic .NET or Visual Basic 2005, visit the following MSDN Web site:

Modification Type:MajorLast Reviewed:1/27/2006
Keywords:kbvs2005swept kbvs2005applies kbmigrate kbprb KB311338