Create a VB application that will perform the following tasks. The user will ent
ID: 3665077 • Letter: C
Question
Create a VB application that will perform the following tasks. The user will enter the number of seconds in the textbox. Store the number of seconds in a minute as a constant and use it in the calculations. Store the number of seconds in an hour in a constant and use it in the calculations. Store the number of seconds in a day in a constant and use it in the calculations. Calculate the number of Days, hours, minutes and seconds. For instance, if the user enters 95646 seconds, the Time Calculator will display the results: 1 day, 2 hours, 34 minutes, 6 seconds Display the days, hours, minutes and seconds result in a label control as shown above. Add a Clear button that will clear the textbox, and the label control. Validate user input for nonnumeric and seconds >= 0.Explanation / Answer
I have written the vb code for the same.
There are four variables in the code for days,hours,minutes and seconds.
working vb code:
Public Class Form1
Dim Days,Hours, Minutes, Seconds As Integer
Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
lblDays.Text = "00"
lblHours.Text = "00"
lblMinutes.Text = "00"
lblSeconds.Text = "00"
txtTimeSeconds.Text = ""
txtFormattedTime.Text = ""
End Sub
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate1.Click
Seconds = Integer.Parse(txtTimeSeconds.Text)
Days = Seconds 86400
Seconds = Seconds Mod 86400
Hours = Seconds 3600
Seconds = Seconds Mod 3600
Minutes = Seconds 60
Seconds = Seconds Mod 60
lblDays.Text= Days.ToString.PadLeft(2,"0"c)
lblHours.Text = Hours.ToString.PadLeft(2, "0"c)
lblMinutes.Text = Minutes.ToString.PadLeft(2, "0"c)
lblSeconds.Text = Seconds.ToString.PadLeft(2, "0"c)
txtFormattedTime.Text = Hours.ToString.PadLeft(2, "0"c) & ":" & Minutes.ToString.PadLeft(2, "0"c) & ":" & Seconds.ToString.PadLeft(2, "0"c)
End Sub
End Class