View Single Post
  #1 (permalink)  
Old 07-05-2009, 6:08 PM
subaru_sti subaru_sti is offline
VB.NET Forum Newbie
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Jul 2009
Posts: 27
Reputation: 11
subaru_sti is on a distinguished programming path ahead
Default Enum or Array or something else

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?

Code:
    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
Reply With Quote