Hello all, following code will cause "Index was outside the bounds of the array." as exception:
Code:
Public Class MainWindow
    Dim RxBuffer As Byte() = {}
        Try
            If SerialPort1.BytesToRead <> 0 Then
                For index = 0 To SerialPort1.BytesToRead - 1
                    RxBuffer(index) = SerialPort1.ReadByte
                Next
            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical)
            Application.Exit()
        End Try
End Class
What I tried:
- Switching variable to other type(s).
- Adding/removing "()" and "{}".
- Adding/removing "index + 1" and "index - 1".

Adding "SerialPort1.ReadByte" in a textbox control once a loop works properly for whole data:
Code:
TextBox1.Text = TextBox1.Text & SerialPort1.ReadByte & " "
The goal is to store received bytes in an array to call/change in-application then clear it every time. The length is changeable every time.
Thanks for contribution in advanced.