Public Class Form1
Private Sub Button1cmdRun_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1cmdRun.Click
' Variable declaration & initilization
Dim hour As Integer
Dim minute As Integer
Dim second As Integer
' Validation
If IsNumeric(txbTotal.Text) And txbTotal.Text Then >= 0 Then
' Total number of seconds
Dim totalSeconds As Integer = CInt(txbTotal.Text)
' Calculation
hour = totalSeconds \ 3600
minute = (totalSeconds Mod 3600) \ 60
second = totalSeconds Mod 60
' Output result
lblResult.Text = "H: " & CStr(hour) & " M: " & CStr(minute) & " S: " & CStr(second)
Else
MessageBox.Show("Invalid input.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
txbTotal.Clear()
End If
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txbTotal.TextChanged
End Sub
Private Sub lblResult_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblResult.Click
End Sub
End Class
Whenever I run the program and I enter text into the label the program crashes. When I type in a negative number the message box works. How do I fix this?
Thanks.