Hey, I'm using VB and want to write code to convert seconds to min. and secs like this:
220 secs. to xx:xx
hope this makes sense
any help appreciated
Printable View
Hey, I'm using VB and want to write code to convert seconds to min. and secs like this:
220 secs. to xx:xx
hope this makes sense
any help appreciated
Using the Mod Operator is one possibility. The following suggests, but is not VB code.
40 = 220 Mod 60
(220 - 40 ) / 60 = 3
220 seconds = 3:40
Does the above give you a clue?
I understand some, but where did you get 40 in the first place?
Dident make much sense to me ither, until i looked it over a few more times. i basicaly took his stuff and converted it to vb
Dim minutes, seconds As Integer
Const TimeInSeconds = 220
Private Sub Form_Load()
seconds = TimeInSeconds Mod 60
minutes = (TimeInSeconds - seconds) / 60
MsgBox (minutes & ":" & seconds)
End Sub
Hipopony66: The Mod Operator works on integer operands, and gives the remainder after dividing.
200 / 60 = 3, with a remainder of 40
Hence 40 = 220 Mod 60
You can use:
minutes = TimeInSeconds \ 60
instead of:
minutes = (TimeInSeconds - seconds) / 60
to find the no. of mins.