VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



A 1 Line Seconds To Minutes

by Feet (2 Submissions)
Category: Math/Dates
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (7 Votes)

This is a function to make seconds into minutes with just one line of code! It's completely commented and very easy to understand. I've seen some other one's that were like 20 or 30 linez long so i made this one. Very good for an mp3 player. I have more lines of comments than i do code :/

Assumes
you can have decimals at the end of your seconds like "126.33467" it would round that to "02:06" anything .5 or under round down, anything .5 or up rounds up.
Code Returns
It returns "00:00" in minutes then seconds like "02:52" after u put in 172.
API Declarations
u don't even have to dim anything!

Rate A 1 Line Seconds To Minutes

Function SecsToMins(Secs As Integer)
If Secs < 60 Then SecsToMins = "00:" & Format(Secs, "00") Else SecsToMins = Format(Secs / 60, "00") & ":" & Format(Secs - Format(Secs / 60, "00") * 60, "00")
'if the seconds are less than 60 it will put a "00:" in front of it and the seconds formatted so if it was 6 seconds then it would be 06
'using format is pretty helpful
'if the seconds are 60 or are more than 60 it will
'divide the amount of seconds by 60 to get minutes
'then comes the harder to understand part(for some people)
'to get the seconds you have to format your seconds by 60 so there are no decimals. Then you multiple that by 60 and take that number away from the total seconds
'it took me awhile to figure out that i needed the format in the middle of finding the seconds.
End Function

Download this snippet    Add to My Saved Code

A 1 Line Seconds To Minutes Comments

No comments have been posted about A 1 Line Seconds To Minutes. Why not be the first to post a comment about A 1 Line Seconds To Minutes.

Post your comment

Subject:
Message:
0/1000 characters