Results 1 to 8 of 8

Thread: [RESOLVED] how can I display secs?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    199

    Resolved [RESOLVED] how can I display secs?

    Code:
    private sub GetElapsed()
    CurrentElapse = DateDiff("n", Now, EndLog)
    
    txtElapse.Text = Formatter(CurrentElapse) 
    end sub
    Code:
    Public Function Formatter(b As Long) As String
      If (b Mod 60) < 30 Then
        Formatter = Str(FormatNumber(b / 60, 0)) & " hrs " & (b Mod 60) & " mins "
      Else
        Formatter = Str(FormatNumber(b / 60, 0) - 1) & " hrs " & (b Mod 60) & " mins"
      End If
    End Function
    how can I include secs to display?
    Last edited by tokneneng; Jan 3rd, 2007 at 12:32 AM.

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    199

    Re: how can I display secs?

    I did try it.. but it won't display the real time elapse... with code above my problem is seconds only....

    thank you for your reply...

    the code is in timer... so it will have a real elapse time...

  3. #3
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: how can I display secs?

    VB Code:
    1. Private Sub GetElapsed()
    2.     Dim CurrentElapse As Long
    3.     CurrentElapse = DateDiff("s", Now, EndLog)
    4.     txtElapse.Text = (CurrentElapse \ 3600) & " hrs " & _
    5.         ((CurrentElapse Mod 3600) \ 60) & " mins " & _
    6.         (CurrentElapse Mod 60) & " secs"
    7. End Sub

  4. #4
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: how can I display secs?

    Quote Originally Posted by tokneneng
    I did try it.. but it won't display the real time elapse... with code above my problem is seconds only....

    thank you for your reply...

    the code is in timer... so it will have a real elapse time...
    The whole number portion (or the long portion) of a date/time represents the number of days elapsed. The decimal portion represents the time elapsed, 0 <= time < 1... so dates can be represented using doubles.

    But you can't use Mod with double data types... so my final suggestion is for you to ditch your Formatter() function. With the difference between X and Y, represent decimal portion as minutes:seconds, get the hours from decimal portion and add whole number (days) portion * 24... that wiull get you hours in excess of 24. Then prepend the number of hours (> 24) to previous minutes:seconds info.
    Last edited by leinad31; Jan 2nd, 2007 at 11:17 PM.

  5. #5
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: how can I display secs?

    Have to notice here that he was/is using DateDiff, which returns Long datatype, so depending on how his variables are declared he was/is doing things right; my example only shows that by changing the parameter of DateDiff resolves the problem of gettings seconds.

    Andrew's example above instead is quite wrong: it assings Long to Date, it passes varianted string to Date (to the same variable again without taking old value into account?) and then shows the current time, not the difference that it should display.

    Edit!
    As a note, Andrew has removed his post since
    Last edited by Merri; Jan 2nd, 2007 at 11:46 PM.

  6. #6
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: how can I display secs?

    Yup, noticed it and edited my post with another suggestion which handles the hours (by manipoulating the days info) instead of everything in seconds (which can overflow).

  7. #7
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: how can I display secs?

    Quote Originally Posted by Merri
    Andrew's example above instead is quite wrong: it assings Long to Date, it passes varienated string to Date (to the same variable again without taking old value into account?) and then shows the current time, not the difference that it should display.
    Oops I didn't realise this before... thanks

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    199

    Re: how can I display secs?

    thankz Merri all work now... got it thank you guys...

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