Saturday, November 12, 2011

Saturday 11.12.11

Module Module1

Sub Main()
Console.WriteLine("**** Fun With Eums ****")


Dim day As DayOfWeek
Dim cc As ConsoleColor

EvaluateEnum(day)
EvaluateEnum(cc)

End Sub

Sub EvaluateEnum(ByVal e As [Enum])
Console.WriteLine("=> Information about {0}", e.GetType().Name)

Console.WriteLine("Underlying storage type: {0}", [Enum].GetUnderlyingType(e.GetType()))


'get all name/value pairs for incoming parameters
Dim enumData As Array = [Enum].GetValues(e.GetType())
Console.WriteLine("This enum has {0} members.", enumData.Length)

'now show the string name and associated value
For i As Integer = 0 To enumData.Length - 1
Console.WriteLine("Name: {0}, Value: {1}", enumData.GetValue(i).ToString(), CInt(enumData.GetValue(i)))
Next
Console.WriteLine()
End Sub
End Module


Module Module1

Structure Point
Public X, Y As Integer

Sub Display()
Console.WriteLine("X = {0}, Y = {1}", X, Y)
End Sub

Sub Increment()
X += 1 : Y += 1
End Sub

Sub Decrement()
X -= 1 : Y -= 1
End Sub

'recall that the 'x' format flag displays the data in hex format
Function PointAsHexString() As String
Return String.Format("X = {0:X}, Y = {1:X}", X, Y)
End Function
End Structure


Sub Main()
Console.WriteLine("***** A First Look At Structures *****")
'create an initial point
Dim myPoint As New Point()
myPoint.X = 349
myPoint.Y = 76
myPoint.Display()

'adjust the X and Y values
myPoint.Increment()
myPoint.Display()
Console.WriteLine("Point in hex: {0}", myPoint.PointAsHexString())
End Sub
End Module

No comments: