I'm having issues with this program, I keep getting an error with the substrings on the "second" part...
It's an oven timer ...display is supposed to be like this 1:11:11, hour minute second....any help will be greatly appreciated....thank you
Code:Private Sub startButton_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles startButton.Click Dim second As Integer Dim minute As Integer Dim hour As Integer ' ensure that timeIs has 5 characters timeIs = timeIs.PadLeft(5, "0"c) ' extract seconds minutes and hours second = Convert.ToInt32(timeIs.Substring(3)) minute = Convert.ToInt32(timeIs.Substring(1, 2)) hour = Convert.ToInt32(timeIs.Substring(0, 1)) ' create Time object to contain time entered by user timeObject = New Time(hour, minute, second) displayLabel.Text = String.Format("{0:D1}:{1:D2}:{2:D2}", timeObject.Hour, timeObject.Minute, timeObject.Second) timeIs = "" ' clear timeIs for future input clockTimer.Enabled = True ' start timer windowPanel.BackColor = Color.Yellow ' turn "light" on End Sub ' startButton_Click ' event handler to clear input Private Sub clearButton_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles clearButton.Click ' reset each property or variable to its initial setting displayLabel.Text = "Microwave Oven" timeIs = "" timeObject = Nothing clockTimer.Enabled = False windowPanel.BackColor = Control.DefaultBackColor End Sub ' clearButton_Click ' method to display formatted time in timer window Private Sub DisplayTime() Dim hour As Integer Dim second As Integer Dim minute As Integer Dim display As String ' String displays current input ' if too much input entered If timeIs.Length > 5 Then timeIs = timeIs.Substring(0, 5) End If display = timeIs.PadLeft(5, "0"c) ' extract seconds minutes and hours second = Convert.ToInt32(timeIs.Substring(3)) minute = Convert.ToInt32(timeIs.Substring(1, 2)) hour = Convert.ToInt32(timeIs.Substring(0, 1)) ' display number of hours ":" minutes, ":" and number of seconds displayLabel.Text = String.Format("{0:D1}:{1:D2}:{2:D2}", hour, minute, second) End Sub ' DisplayTime ' event handler displays new time each second Private Sub clockTimer_Tick(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles clockTimer.Tick ' perform countdown, subtract one second If timeObject.Second > 0 Then timeObject.Second -= 1 displayLabel.Text = String.Format("{0:D1}:{1:D2}:{2:D2}", timeObject.Hour, timeObject.Minute, timeObject.Second) ElseIf timeObject.Minute > 0 Then timeObject.Minute -= 1 timeObject.Second = 59 displayLabel.Text = String.Format("{0:D1}:{1:D2}:{2:D2}", timeObject.Hour, timeObject.Minute, timeObject.Second) ElseIf timeObject.Hour > 0 Then timeObject.Hour -= 1 timeObject.Minute = 59 timeObject.Second = 59 displayLabel.Text = String.Format("{0:D1}:{1:D2}:{2:D2}", timeObject.Hour, timeObject.Minute, timeObject.Second) Else ' countdown finished clockTimer.Enabled = False ' stop timer Beep() displayLabel.Text = "Done!" ' inform user time is finished windowPanel.BackColor = Control.DefaultBackColor End If End Sub ' clockTimer_Tick End Class ' MicrowaveOvenFormCode:Public Class Time ' declare Integers for hour minute and second Private minuteValue As Integer Private secondValue As Integer Private hourValue As Integer ' Time constructor, minute and second supplied Public Sub New(ByVal hh As Integer, ByVal mm As Integer, ByVal ss As Integer) Hour = hh ' invokes Hour set accessor Minute = mm ' invokes Minute set accessor Second = ss ' invokes Second set accessor End Sub ' New ' property Hour Public Property Hour() As Integer ' return Hour value Get Return hourValue End Get ' end of Get accessor ' set Hour value Set(ByVal value As Integer) 'if hour value entered is valid If (value < 10) Then hourValue = value Else hourValue = 0 ' set invalid input to 0 End If End Set ' end of Set accessor End Property ' Hour ' property Minute Public Property Minute() As Integer ' return Minute value Get Return minuteValue End Get ' end of Get accessor ' set Minute value Set(ByVal value As Integer) 'if minute value entered is valid If (value < 60) Then minuteValue = value Else minuteValue = 0 ' set invalid input to 0 End If End Set ' end of Set accessor End Property ' Minute ' property Second Public Property Second() As Integer ' return Second value Get Return secondValue End Get ' end of Get accessor ' set Second Value Set(ByVal value As Integer) ' if second value entered is valid If (value < 60) Then secondValue = value Else secondValue = 0 ' set invalid input to 0 End If End Set ' end of Set accessor End Property ' Second End Class ' Time




Reply With Quote
