Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

VB programming Time conversion create a form that allows a user to enter time va

ID: 3721129 • Letter: V

Question

VB programming

Time conversion





create a form that allows a user to enter time values in (seconds).

there should be 3 buttons ( Convert), ( Clear), (Exit).

when ( convert) is clicked the application should convert ( Seconds) value in terms of day, hour, minute and seconds and show value label.

Sample.1

input: 100 seconds.
Output: 1 minute 40 seconds.

Sample 2.

input: 10000 seconds
output: 1 day 3 hours 46 minutes 40 seconds.

Note:::

1 minute = 60 seconds
1 hour = 3600 seconds
1 day= 86400 seconds.

(Clear )- to enter new number of seconds or correct input.

(Exit ) - Leave app

Explanation / Answer

I have used TimeSpan class from .NET library to achieve what is expected.

Public Class Form1

Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click

txtTimeInSeconds.Text = ""

txtExpectedTime.Text = ""

End Sub

Private Sub btnConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate1.Click

Dim Seconds as Integer

Seconds = Integer.Parse(txtTimeInSeconds.Text)

  

  

Dim flag As TimeSpan = TimeSpan.FromSeconds(Seconds)

txtExpectedTime.Text = flag.Days.ToString.PadLeft(2, "0"c) & "days" & _

flag.Hours.ToString.PadLeft(2, "0"c) & "hours" & _

flag.Minutes.ToString.PadLeft(2, "0"c) & "mins" & _

flag.Seconds.ToString.PadLeft(2, "0"c) & "secs"

End Sub

Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles ExitProgram.Click

Application.Exit()

End If

End Sub

End Class