In: Computer Science
Time Calculator ( PROGRAM VBA EXCEL)
Create a application that lets the user enter a number of seconds and produces output according to the following criteria:
There are 60 seconds in a minute. If the number of seconds entered by the user is greater than or equal to 60, the program should display the number of minutes in that many seconds.
There are 3,600 seconds in an hour. If the number of seconds entered by the user is greater than or equal to 3,600, the program should display the number of hours in that many seconds.
There are 86,400 seconds in a day. If the number of seconds entered by the user is greater than or equal to 86,400, the program should display the number of days in that many seconds.
In VBA Excel, Add a module and write the below sub inside it. Then create a Form Control button and assign the macro to the button. You can now call the sub to run the program
============================================================================
Option Explicit
Sub CONVERT_SECONDS()
Dim seconds As Long
seconds = CLng(InputBox("Enter the number of seconds: "))
If seconds < 60 Then
MsgBox "That is equal to " & seconds & " seconds."
ElseIf seconds < 3600 Then
MsgBox "That is equal to " & seconds / 60 & "
minutes."
ElseIf seconds < 86400 Then
MsgBox "That is equal to " & seconds / 3600 & "
hours."
Else
MsgBox "That is equal to " & seconds / 86400 & "
days."
End If
End Sub