subaru_sti
Active member
- Joined
- Jul 4, 2009
- Messages
- 34
- Programming Experience
- Beginner
Hello.
I have the following code which obtains the compass direction from a degree value. I'm new to VB.Net and was wondering what is the best way to store the values, in an Enum or an Array?
Stephen
I have the following code which obtains the compass direction from a degree value. I'm new to VB.Net and was wondering what is the best way to store the values, in an Enum or an Array?
VB.NET:
Public Enum CardinalPoints
N = 1 Or 9
NE = 2
E = 3
SE = 4
S = 5
SW = 6
W = 7
NW = 8
End Enum
Public Class Helper
Public Function DegreesToCardinalMark(ByVal degrees As Double) As String
Dim compassPoint As Integer
If degrees > 360 Then Throw New ArgumentOutOfRangeException("Degrees cannot be greater than 360.")
If degrees < 0 Then Throw New ArgumentOutOfRangeException("Degrees cannot be less than 0.")
compassPoint = CInt(Math.Truncate(((degrees / 360) * 8) + 0.5) + 1)
Return CardinalPoints.GetName(GetType(CardinalPoints), compassPoint).ToString()
End Function
End Class
Stephen