Building Char Strings, Chars ASCII > 127 & Chinese Windows
-
An app (VB) that we have had running for a few years now has been working fine on American and European versions of Windows. Now someone has tried to run it on Chinese Windows, and it's not working. I have traced it down to one specific thing, as follows: The code builds up Modbus communications messages one byte at a time using VB's Chr$() function, like this: strMessage = Chr$(1) & Chr$(3) & Chr$(0) & Chr$(48) ... etc. Now, as we all know an unsigned byte can be from 0 - 255. Also, in a single byte character system, ASCII characters also go from 0 to 255. Thus, it is quite natural to want to add such bytes beyond 127, which would be negative values _if_treated_as_signed_bytes_: strMessage = strMessage & Chr$(245) & Chr$(136) Now, on most systems this works just dandy. But I have discovered that whenever we try to add a byte (character) > 127 under Chinese Windows, it instead ends up with 0 there - it doesn't seem to get it right. All suspicions point to MBCS (multi-byte character set) issues, but I was under the impression that VB handles this automatically. Can anyone suggest how I might successfully add bytes > 127 to a VB string, using VB methods? When I get totally desperate I can call to a C++ DLL to do it, but there's a fair bit of work rewriting the VB code for that so it's a very last resort! -- Jason Teagle jason@teagster.co.uk ----------------------------------------------------------- A list of programming resources I use: ML: www.windev.org, www.codecipher.com, www.beginthread.com MB: www.codeguru.com, www.codeproject.com NG: comp.lang.java.* OI: www.php.net -----------------------------------------------------------
-
An app (VB) that we have had running for a few years now has been working fine on American and European versions of Windows. Now someone has tried to run it on Chinese Windows, and it's not working. I have traced it down to one specific thing, as follows: The code builds up Modbus communications messages one byte at a time using VB's Chr$() function, like this: strMessage = Chr$(1) & Chr$(3) & Chr$(0) & Chr$(48) ... etc. Now, as we all know an unsigned byte can be from 0 - 255. Also, in a single byte character system, ASCII characters also go from 0 to 255. Thus, it is quite natural to want to add such bytes beyond 127, which would be negative values _if_treated_as_signed_bytes_: strMessage = strMessage & Chr$(245) & Chr$(136) Now, on most systems this works just dandy. But I have discovered that whenever we try to add a byte (character) > 127 under Chinese Windows, it instead ends up with 0 there - it doesn't seem to get it right. All suspicions point to MBCS (multi-byte character set) issues, but I was under the impression that VB handles this automatically. Can anyone suggest how I might successfully add bytes > 127 to a VB string, using VB methods? When I get totally desperate I can call to a C++ DLL to do it, but there's a fair bit of work rewriting the VB code for that so it's a very last resort! -- Jason Teagle jason@teagster.co.uk ----------------------------------------------------------- A list of programming resources I use: ML: www.windev.org, www.codecipher.com, www.beginthread.com MB: www.codeguru.com, www.codeproject.com NG: comp.lang.java.* OI: www.php.net -----------------------------------------------------------
Note: the answer was provided somewhere else - use ChrB$() instead of Chr$() - I didn't know this existed :)