Code:
Public Enum CardinalPoints
N = 1 Or 9
NE = 2
E = 3
SE = 4
S = 5
SW = 6
W = 7
NW = 8
End Enum
Stephen,
Enums work just fine. However, I would start by having N at 0, then going up from there. IOW,
Code:
Public Enum CardinalPoints
N = 0
NE = 1
E = 2
SE = 3
S = 4
SW = 5
W = 6
NW = 7
End Enum
Code:
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.")
If degrees = 360 Then degrees = 0
compassPoint = CInt(Math.Truncate((degrees / 360) * 8) + 0.5)
Return CardinalPoints.GetName(GetType(CardinalPoints), compassPoint).ToString()
End Function
End Class
Also, since you came up with the use of your program for compass directions, I'm a old-school navigator myself; those eight directions are not good enough for me. I'm going to include a couple of websites for myself and other people (although few and far between) would like:
[ame=http://en.wikipedia.org/wiki/Compass_rose]Compass rose - Wikipedia, the free encyclopedia[/ame]
[ame=http://en.wikipedia.org/wiki/Boxing_the_compass]Boxing the compass - Wikipedia, the free encyclopedia[/ame]
NOTE about Boxing the compass: Although, step 4 of the instructions say to increment the result by 1, I would start the table's numbering scheme at 0 (to correspond to
VB.NET's standards)
Randy