Results 1 to 15 of 15

Thread: converting seconds

Hybrid View

  1. #1
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: converting seconds

    \ is integer division, so 7600 \ 1000 = 7
    / is normal division, so 7600 / 1000 = 7.6

    the format function performs rounding, so you end up with 8 instead of 7.

    your function won't work for a couple of reasons (try putting in 77600 for example). Try this:
    VB Code:
    1. Private Function ConvertMilliSeconds(ByVal mSec As Long) As String
    2.     ConvertMilliSeconds = Format$(mSec \ 3600000, "00") & ":" & _
    3.                      Format$((mSec Mod 3600000) \ 60000, "00") & ":" & _
    4.                      Format$((mSec Mod 60000) / 1000, "00.000")
    5. End Function

  2. #2

    Thread Starter
    Hyperactive Member Troy Lundin's Avatar
    Join Date
    May 2006
    Posts
    489

    Re: converting seconds

    Ok, I rewrote it like so:

    VB Code:
    1. Private Function cSeconds(ByVal mSec As Long) As String
    2. mSec = 30000
    3.     Select Case mSec
    4.        
    5.         Case Is >= 600, Is < 3600
    6.             cSeconds = _
    7.             Format$((mSec Mod 3600) \ 60, "00") & ":" & _
    8.             Format$(mSec Mod 60, "00")
    9.         Case Is < 600
    10.             cSeconds = "0:" & _
    11.             Format$(mSec Mod 60, "00")
    12.         Case Is >= 3600, Is < 36000
    13.             cSeconds = _
    14.             Format$(mSec \ 3600, "00") & ":" & _
    15.             Format$((mSec Mod 3600) \ 60, "00") & ":" & _
    16.             Format$(mSec Mod 60, "00")
    17.     End Select
    18.    
    19. End Function

    Now there is one problem. With mSec at 30000 it completely ignores the first part of the string (the hours) and it returns "20:00". What is going on? No matter what number I make mSec, it will not show the hours. I tried 3599 which returned "59:59" then 3600 which returned "00:00" then 3601 which returned "00:01"

    Why is it not showing the hours?
    Prefix has no suffix, but suffix has a prefix.

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