Thursday, December 2, 2010

Thursday, 12/2/2010


Imports System
Public Class time
'public member variables
Private mYear As Integer
Private mMonth As Integer
Private mDate As Integer
Private mHour As Integer
Private mMinute As Integer
Private mSecond As Integer

'this is my first time to use properties
Property Hour() As Integer
Get
Return mHour
End Get
Set(ByVal value As Integer)
mHour = value
End Set
End Property

'public accessor methods

Public Sub DisplayCurrentTime()
Console.WriteLine( _
"{0}/{1}/{2} {3}:{4}:{5}", _
mMonth, mDate, mYear, mHour, mMinute, mSecond)
End Sub 'DisplayCurrentTime

'constructors
Public Sub New(ByVal dt As System.DateTime)
mYear = dt.Year
mMonth = dt.Month
mDate = dt.Date
mHour = dt.Hour
mMinute = dt.Minute
mSecond = dt.Second
End Sub 'new

Public Sub New( _
ByVal mYear As Integer, _
ByVal mMonth As Integer, _
ByVal mDate As Integer, _
ByVal mHour As Integer, _
ByVal mMinute As Integer, _
ByVal mSecond As Integer)
Me.mYear = mYear
Me.mMonth = mMonth
Me.mDate = mDate
Me.mHour = mHour
Me.mHour = mMinute
Me.mSecond = mSecond
End Sub 'new

End Class 'Time

Module Module1

Sub main()
Dim currentTime As System.DateTime = System.DateTime.Now
Dim time1 As New time(currentTime)
time1.DisplayCurrentTime()

'extract the hour to a local variable
Dim theHour As Integer = time1.Hour

'display the local variable
Console.WriteLine("Retrieved the hour: {0}", theHour)

'add one to the local variable
theHour += 1
'write teh time back to the object
time1.Hour = theHour

'dispaly the result
Console.WriteLine("Update the hour: {0} ", _
time1.Hour)

Console.ReadLine()
End Sub
End Module

No comments: