F freetoair Member Licensed User Longtime User Sep 9, 2015 #1 I need to receive 2-byte coded unusual and this routine works pretty chaotic. Is the problem in the deletion of the buffer? When an error occurs get a message on the screen: An error has occurred in sub: main_astreams_nevdata (java line: 465) java.lang.ArrayIndexOutOfBoundsException: length = 1; Index = 1 Code: Copy Sub Astreams_NewData (Buffer() As Byte) Dim r As Int = 0 r = ((Bit.ShiftRight(Buffer(0),4) * 100) + (Bit.ShiftRight(Buffer(1),4) * 10) + (Bit.And(Buffer(1),15))) * 2 skbValue_ValueChanged(r, False) 'Sub that refreshes the LED bar End Sub
I need to receive 2-byte coded unusual and this routine works pretty chaotic. Is the problem in the deletion of the buffer? When an error occurs get a message on the screen: An error has occurred in sub: main_astreams_nevdata (java line: 465) java.lang.ArrayIndexOutOfBoundsException: length = 1; Index = 1 Code: Copy Sub Astreams_NewData (Buffer() As Byte) Dim r As Int = 0 r = ((Bit.ShiftRight(Buffer(0),4) * 100) + (Bit.ShiftRight(Buffer(1),4) * 10) + (Bit.And(Buffer(1),15))) * 2 skbValue_ValueChanged(r, False) 'Sub that refreshes the LED bar End Sub
RandomCoder Well-Known Member Licensed User Longtime User Sep 9, 2015 #2 You are not getting the data you expect. Buffer(1) is throwing the error because there is only one byte present i.e. length=1 in the error message. You could guard against this error by checking the size of the array of bytes before running your function. Upvote 0
You are not getting the data you expect. Buffer(1) is throwing the error because there is only one byte present i.e. length=1 in the error message. You could guard against this error by checking the size of the array of bytes before running your function.
F freetoair Member Licensed User Longtime User Sep 9, 2015 #3 All right, I just added: If (Buffer.Length = 2) Then ..... End If now works great. Thank you RandomCoder Upvote 0
All right, I just added: If (Buffer.Length = 2) Then ..... End If now works great. Thank you RandomCoder