2

I had a program with code conversion VB6 (on WinXP 32bit) which sends command to RS232 radio modem. I rewrite the code into VB.NET (WinX 64bit) but the output string to serial port is different. For example:

VB6 code:

Chr$(193)

Output is:

VB6output

VB.NET code:

Convert.ToChar(193)

Output is:

VB.Netoutput

I think this has something to do with character tables but cannot find any solution Thanks for any info

Andrew Morton
  • 24,203
  • 9
  • 60
  • 84
GKS
  • 21
  • 1
  • How are you getting from `Convert.ToChar(193)` to the output you show for that? Is it necessary to use a string between 193 and the output? – Andrew Morton Feb 02 '22 at 10:29
  • Mmm, If I remember correctly Chr$() transforms to ASCII, and Convert.ToChar() does to UNICODE ... – J.Salas Feb 02 '22 at 10:36
  • If you need to send `&HC1` to the port, then send `&HC1`. – GSerg Feb 02 '22 at 10:40
  • @Andrew Morton instead to send it to serial i write to file, and yes i need the whole ascii table (0..255) – GKS Feb 02 '22 at 12:10
  • @GKS You can write bytes to a file, it doesn't have to be a string. – Andrew Morton Feb 02 '22 at 12:15
  • @GSerg don't know how excatly the communicarion is working, the original code sends string to serial. i'll try to send it as byte, the &HC1 was an example, the whole command can be tenths of characters – GKS Feb 02 '22 at 12:15
  • What kind of code is doing the actual sending in VB6? – GSerg Feb 02 '22 at 13:28
  • 1
    The Strings class/module in VB.NET also has Chr and ChrW - why do you feel the need to reproduce this? – Dave Doknjas Feb 02 '22 at 16:28

1 Answers1

-1

According to this link from Microsoft, Convert.toChar(...) does this:

Converts the value of the specified object to a Unicode character.

My guess is you're getting a unicode, since instead of C1, you're getting C3 81 (Unicode can take 1-4 bytes per char). Perhaps something like this answer would help:

((char)0x00C1).ToString();

User51
  • 887
  • 8
  • 17