Results 1 to 3 of 3

Thread: converting number to seconds and minutes

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2000
    Location
    USA
    Posts
    26

    Post

    This is what i want to do...

    Im making an mp3 player, and i use the current position * the total length of the song divided by 100 which gives me the number it would be on. But the numbers are like 97.34 , and i just wanted to know how i could just convert that to 01:37. I tried all sorts of stuff, but what I tried didnt work for me. Any suggestions? (if you are going to say , just run a timer that counts how long the song has been playing, i dont want to do that because if the user fastforwards or rewinds in the song, it will be totally off.)

  2. #2
    Fanatic Member
    Join Date
    Oct 1999
    Location
    MA, USA
    Posts
    523

    Post

    If you say that 97.34 equals to 1 minute and 37 seconds then I can assume that you don't care about the decimal value. If that's the case then use this code:
    Code:
        Dim Number
        Dim inMinutes As Integer
        Dim inSeconds As Integer
        
        Number = 97.34
        
        inMinutes = Number \ 60
        
        inSeconds = Number - (inMinutes * 60)
        
        MsgBox "Minutes: " & inMinutes & vbCrLf & "Seconds: " & inSeconds
    I hope that this is what you mean

    Edited by QWERTY on 02-27-2000 at 01:06 AM

  3. #3
    New Member
    Join Date
    Feb 2000
    Location
    Moncton, NB, Canada
    Posts
    4

    Post decimals to minutes and seconds

    take the integer value of the number divided by 60
    This gives the number of minutes

    int(157.5/60) = 2

    subtract this integer number times sixty from the original number

    157.5 - int(157.5/60)*60 = 37.5

    Present it as a string

    str$(int(157.5/60)) & ":" & str$(157.5-int(157.5/60)*60)
    gives you 2:37.5

    Or it should if I haven't made a stupid typo


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width