My first error is showing a green line under NEW at aproximately line 11 and 18. Not sure how to get line numbers to show up?
My next problem comes in at the Private Sub addMinuteButton there's a blue line under the incrementsMinutes.Click and it says: Handle clause requires a WithEvents variable defined in the containing type or one of it's base types.
Lastly the " & time.ToUniversalString towards the end of the code created a private function on it's own? Is the throw new exception going to work?
Public Class Time
'declare integer instance variables for the hour, minute and second
Private hourValue As Integer ' 0-23
Private minuteValue As Integer ' 0-59
Private secondValue As Integer '0-59
'Time constuctor with hour, minute and second as optional parameters
Public Sub New(Optional ByVal h As Integer = 12, Optional ByVal m As Integer = 0, Optional ByVal s As Integer = 0)
SetTime(h, m, s) 'call SetTime with three arguments
End Sub
' Time constructor: another Time object supplied
Public Sub New(ByVal t As Time)
SetTime(t.hourValue, t.minuteValue, t.secondValue)
End Sub 'New
' set a new time value using universal time, check validity of the data
Public Sub SetTime(ByVal h As Integer, ByVal m As Integer, ByVal s As Integer)
Hour = h ' Set accessor validates the hour
Minute = m ' Set accessor validates the minute
Second = s ' Set accessor validates the second
End Sub 'Set Time
' property Hour
Public Property Hour() As Integer
Get ' return hourValue
Return hourValue
End Get
Set(ByVal value As Integer) ' set HourValue
If (value >= 0 AndAlso value < 24) Then
hourValue = value
Else
Throw New ArgumentOutOfRangeException
End If
End Set
End Property 'Hour
'property Minute
Public Property Minute() As Integer
Get ' return minuteValue
Return minuteValue
End Get
Set(ByVal value As Integer) ' set minuteValue
If (value >= 0 AndAlso value < 60) Then
minuteValue = value
Else
Throw New ArgumentOutOfRangeException
End If
End Set
End Property
'property Second
Public Property Second() As Integer
Get
Return secondValue
End Get
Set(ByVal value As Integer) ' set secondValue
If (value > -0 AndAlso value < 60) Then
secondValue = value
Else
Throw New ArgumentOutOfRangeException
End If
End Set
End Property 'Hour
Dim time As New Time() ' construct Time with zero arguments
' invoked when user clicks the Add 1 to Second button
Private Sub addSecondButton_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles incrementSecondButton.Click
time.Second = (time.Second + 1) Mod 60 ' add 1 to Second
If time.Second = 0 Then
time.Minute = (time.Minute + 1) Mod 60 ' add 1 to Minute
End If
UpdateDisplay() ' update the TextBoxes and output Labels
End Sub ' addSecondButton_Click
Private Sub addHourButton_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles incrementHourButton.Click
time.Hour = (time.Hour + 1) Mod 24
UpdateDisplay()
End Sub
Private Sub addMinuteButton_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles incrementMinuteButton.Click
time.Minute = (time.Minute + 1) Mod 60
If time.Minute = 0 Then
time.Hour = (time.Hour + 1) Mod 24
End If
UpdateDisplay()
End Sub
' set time based on TextBox values
Private Sub setTimeButton_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles setTimeButton.Click
' ensure that hour, minute and second are in range
Try
If setHourTextBox.Text <> String.Empty Then
time.Hour = Convert.ToInt32(setHourTextBox.Text)
End If
If setMinuteTextBox.Text <> String.Empty Then
time.Minute = Convert.ToInt32(setMinuteTextBox.Text)
End If
If setSecondTextBox.Text <> String.Empty Then
time.Second = Convert.ToInt32(setSecondTextBox.Text)
End If
Catch ex As ArgumentOutOfRangeException
MessageBox.Show("The hour, minute or second was out of range",
"Out of Range", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
UpdateDisplay() ' update the TextBoxes and output Labels
End Sub ' setTimeButton_Click
' update time display
Private Sub UpdateDisplay()
setHourTextBox.Text = Convert.ToString(time.Hour)
setMinuteTextBox.Text = Convert.ToString(time.Minute)
setSecondTextBox.Text = Convert.ToString(time.Second)
output1Label.Text = ("Hour: " & time.Hour & "; Minute: " &
time.Minute & "; Second: " & time.Second)
output2Label.Text = ("Standard time is: " & time.ToString() &
"; Universal Time is: " & time.ToUniversalString())
End Sub ' UpdateDisplay
Private Function ToUniversalString() As String
Throw New NotImplementedException
End Function
End Class

New Topic/Question
Reply



MultiQuote




|