1

I am receiving data from serial port RS232 like [00000] continuously per 100 ms, but if i use usb to serial converter data is splitting into multiple parts if i append that in a text box i am getting output like [00000][00000][00000][00000][00000], here comes the problem i want to pick the each array separately like [00000] what i am getting is

[
0 
000
0
]

so i tried to concat it in a variable upto the string getting into the length of 7, if it 7 i will write it into another variable and clear pervious array still i could't achieve the result.

Dim k As String
k = k & [text]
If k.Length = 7 Then
   Me.RichTextBox1.Text = k
   k = ""
End If

how to get the desired result.

  • 1
    Check each `[text]` before appending to `k` to see if there are any unprintable characters like char(0), 13, etc, which will result in length being more than expected. Let's say at the end of each `[text]`, there is chr(0) appended at the end, so the `k.length` will be 2, then 4 (2+2), then 8 (4+4), and so on. So your if statement will never hit true since it checks for 7. If there are any unprintable characters, trim them first before apending to your variable. – ajakblackgoat Feb 13 '19 at 10:16
  • @ajakblackgoat exactly the same i am facing, thanks i will try – Pattatharasu Nataraj Feb 13 '19 at 10:19
  • I suggest you printout the [text].length to debug output to see what their actual length is for each data received. – ajakblackgoat Feb 13 '19 at 10:21
  • i did that already, result is like 2, 1 5, 4, 1, 1, 2 – Pattatharasu Nataraj Feb 13 '19 at 10:26
  • Exactly, for the example data input in your question, it should be 1, 1 3, 1, 1 – ajakblackgoat Feb 13 '19 at 10:32

0 Answers0