Hi
For those of you that saw the other thread, i've managed to find out why it wasnt working and find a work around, but i dont know why one works and not the other. Could someone have a look and tell me what they think please?
This is the original code. It was largely working fine, but the first char was chr(153) or Hex value 99. It would convert this into a ?, hex value 3F or Chr(63). I'm guessing it was reading the first character from the string as a ? as its an unprintable symbol, and then outputting this to an actual ? in the conversion.
However I tried the change below (ok so my boss did, who has never used .Net before) and almost annoyingly it worked.
Can someone please tell me why the first piece of code didnt work but the second did? Why could it not convert it correctly as part of a string, but it could byte by byte.
Obviously its working, which i'm happy about, but i would like to know why if anyone can help please?
Thanks
For those of you that saw the other thread, i've managed to find out why it wasnt working and find a work around, but i dont know why one works and not the other. Could someone have a look and tell me what they think please?
This is the original code. It was largely working fine, but the first char was chr(153) or Hex value 99. It would convert this into a ?, hex value 3F or Chr(63). I'm guessing it was reading the first character from the string as a ? as its an unprintable symbol, and then outputting this to an actual ? in the conversion.
Visual Basic:
mobjClient = New TcpClient("172.28.46.27", 3500)
Dim b() As Byte = System.Text.Encoding.ASCII.GetBytes(sMessage)
Dim s As IO.Stream = mobjClient.GetStream
s.Write(b, 0, b.Length)
s.Flush()
s.Close()
However I tried the change below (ok so my boss did, who has never used .Net before) and almost annoyingly it worked.
Visual Basic:
mobjClient = New TcpClient("172.28.46.27", 3500)
Dim b(sMessage.Length - 1) As Byte
For i As Integer = 0 To sMessage.Length - 1
b(i) = Asc(sMessage.Substring(i, 1))
Next
Dim s As IO.Stream = mobjClient.GetStream
s.Write(b, 0, b.Length)
s.Flush()
s.Close()
Can someone please tell me why the first piece of code didnt work but the second did? Why could it not convert it correctly as part of a string, but it could byte by byte.
Obviously its working, which i'm happy about, but i would like to know why if anyone can help please?
Thanks