# QuestionCalculate angle between bytes value.

#### Damien.darhk

##### Member
Hello, I've an array of bytes that contains Y values of a chart; I need to calculate the angles between each point, so:

Dim numbers = New Byte() {&H0, &H0, &H0, &HA0, &H0, &HA0, &H0, &HA0, &H0, &HA0, &H0, &HA0, &H0, &HA0, &H0, &HA0, &H0, &HA0, &H0, &HA0, &H0, &HA0, &H0, &HA0, &H0, &HA0, &H0, &HA0, &H0, &HA0, &H0, &H0, &H0, &H0, &H1, &HA8, &H1, &H2C, &H0, &HEA, &H0, &HCB, &H0, &HC4, &H0, &HBE, &H0, &HB7, &H0, &HB5, &H0, &HB2, &H0, &HB0, &H0, &HAE, &H0, &HAC, &H0, &HAB, &H0, &HAA, &H0, &H0, &H0, &H0, &H2, &HC, &H1, &H72, &H1, &H2A, &H0, &HFF, &H0, &HED, &H0, &HE3, &H0, &HDB, &H0, &HD5, &H0, &HD1, &H0, &HCE, &H0, &HCB, &H0, &HC8, &H0, &HC4, &H0, &HBD, &H0, &H0, &H0, &H0, &H2, &H87, &H1, &HCA, &H1, &H59, &H1, &H34, &H1, &H1D, &H1, &H15, &H1, &HC, &H1, &H6, &H1, &H3, &H1, &H2, &H1, &H0, &H0, &HFE, &H0, &HFA, &H0, &HF2, &H0, &H0, &H0, &H0, &H3, &H17, &H2, &H30, &H1, &HBA, &H1, &H65, &H1, &H46, &H1, &H38, &H1, &H2E, &H1, &H25, &H1, &H22, &H1, &H1D, &H1, &H18, &H1, &H15, &H1, &HF, &H1, &H6, &H0, &H0, &H0, &H0, &H3, &H99, &H2, &H8B, &H1, &HF3, &H1, &HAB, &H1, &H72, &H1, &H53, &H1, &H43, &H1, &H36, &H1, &H2F, &H1, &H2B, &H1, &H28, &H1, &H22, &H1, &H1B} 'This is the array of points

Dim angleslist As New List(Of Double)
For i = 1 To numbers.Count - 1
angleslist.Add(Math.Atan2(numbers(i) - numbers(i - 1), 1))
Next

but I get System.OverflowException.
I'm missing something?

Last edited:

#### JohnH

##### VB.NET Forum Moderator
Staff member
Your list is type Byte, while Atan2 function returns a Double value.

#### Damien.darhk

##### Member
Your list is type Byte, while Atan2 function returns a Double value.
I already changed it to Double but still get the exception

#### jmcilhinney

##### VB.NET Forum Moderator
Staff member
Shouldn't this:
VB.NET:
``For i = 1 To angleslist.Count - 1``
be this:
VB.NET:
``For i = 1 To numbers.Length - 1``
Surely that would have been obvious if you had bothered to debug.

#### Damien.darhk

##### Member
yes, I posted wrong code, my bad of copy and paste from vs.
The code that give me the problem is that:
Dim angleslist As New List(Of Double)

VB.NET:
``````Dim angleslist As New List(Of Double)
For i = 1 To numbers.Length - 1
angleslist.Add(Math.Atan2(numbers(i) - numbers(i - 1), 1))
Next``````

the error is always the same and it always stop on i=4; I've also tryed to change the numbers() values, but still get this exception.

#### jmcilhinney

##### VB.NET Forum Moderator
Staff member
Learning how to diagnose errors in your code is almost as important as learning how to write code. You obviously don't know what part of that code is causing the problem so that's what you need to find out. You're doing multiple things in one line and you don't know which of those things is the problem. The obvious solution is to not do multiple things on one line. Break it up into multiple lines and do one thing on each line. It will then be obvious which specific thing is causing the issue. This is really the logic of problem-solving in general and not specific to programming but a lot of people seem to abandon all logic when they start programming and think that it works on a different set of rules. It doesn't. Just as you would break a bigger problem into smaller parts in other areas, so you do in programming.

#### Damien.darhk

##### Member
I get the exception with this operation: numbers(i) - numbers(i - 1), when numbers(i) =0 and numbers(i-1) is positive; that did not make any sense for me: negative number are allowed in double type( in this case the calc is 0-160=160);I also put the value in the code by hand instead using variable and it work, but the same value thru a variable not work.

#### JohnH

##### VB.NET Forum Moderator
Staff member
Byte is an immutable value type that represents unsigned integers with values that range from 0 (which is represented by the Byte.MinValue constant) to 255
Negative value is not possible for Byte data type. Since Atan2 also expect Double values as input convert the values to that type also. You can do that with CDbl conversion function. Type Conversion Functions - Visual Basic