Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Building Char Strings, Chars ASCII > 127 & Chinese Windows

Building Char Strings, Chars ASCII > 127 & Chinese Windows

Scheduled Pinned Locked Moved Visual Basic
csharpc++javaphpcom
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jason Teagle
    wrote on last edited by
    #1

    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 -----------------------------------------------------------

    J 1 Reply Last reply
    0
    • J Jason Teagle

      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 -----------------------------------------------------------

      J Offline
      J Offline
      Jason Teagle
      wrote on last edited by
      #2

      Note: the answer was provided somewhere else - use ChrB$() instead of Chr$() - I didn't know this existed :)

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups