Migrating VB6 with non-ASCII characters
by Will Vasquez, on Oct 1, 2024 3:28:11 PM
As you may already know, the Visual Basic Upgrade Companion (VBUC) is the premier tool for converting legacy VB6 applications to .NET.
One of the many scenarios that VBUC supports is the migration of applications containing non-ASCII characters. This is crucial for applications with strings or comments in languages such as Japanese, Chinese, or Hebrew.
Working with encodings, code pages, and regional settings can be complex and often requires a refresher. Scott Hanselman provides an excellent explanation of these basic concepts here: https://www.hanselman.com/blog/computer-things-they-didnt-teach-you-in-school-2-code-pages-character-encoding-unicode-utf8-and-the-bom.
Originally, Visual Basic stored these characters in Unicode, displaying them correctly in the VB6 IDE.
The VBUC generates code files using UTF-8, considering the developer’s regional settings to accurately convert the original characters into their UTF-8 representation.
However, if these settings are not configured correctly, you might end up with garbled text in the migrated application.
So, for a source like this one:
You might end up with this:
Or this:
The answer to this is to simply set the system locale to English during the conversion process, following these steps:
- Open Control Panel
- Click on Clock and Region settings
- Click on Region settings
- Click on Administrative tab
- Click on Change system locale button
- Change the Current system locale to English (United States)
- Click on OK button and restart the computer
- Upgrade the code using the VBUC
- Change the Current system locale to its default value (Japanese in this case) and restart the computer
- Open the generated solution
Now the generated code will be using UTF-8 and will work in any environment you move it to.
As usual, if you have any questions, feel free to reach out and book a session with us: https://www.mobilize.net/talk-to-an-engineer.