Results 1 to 4 of 4

Thread: [RESOLVED] Little bit of math and VB6

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2007
    Location
    Canada
    Posts
    297

    Resolved [RESOLVED] Little bit of math and VB6

    Hey folks.

    Let me set my project up for you, I have one Windows Media Player component, and 3 text boxes.

    In one text box I have coming from WMP the updating value of this output:
    WindowsMediaPlayer1.Controls.currentPositionString
    That shows the position of the currently playing clip in this format: “00:00”

    The next text box I have shows the total duration of the clip:
    WindowsMediaPlayer1.currentMedia.durationString
    Which as well shows the duration of the clip in the “00:00” format.

    I have a third text box that I would like to show how much time is remaining in the clip.

    For example, I would like to be able to have something like:
    WindowsMediaPlayer1.currentMedia.durationString (subtract) WindowsMediaPlayer1.Controls.currentPositionString

    That would take the total duration of the video, and subtract the current position giving the total time remaining. However, I cannot get this to display, does anyone have any suggestions on how I would get this to work?

    Thanks in advance!

  2. #2
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: Little bit of math and VB6

    vb Code:
    1. Private Sub tmrShowTime()
    2.     txtDuration.Text = SecondsToTime(wmp.currentMedia.duration)
    3.     txtPosition.Text = SecondsToTime(wmp.Controls.currentPosition)
    4.     txtRemaining.Text = SecondsToTime(wmp.currentMedia.duration - wmp.Controls.currentPosition)
    5. End Sub
    6.  
    7. Public Function SecondsToTime(ByVal plngSeconds As Long) As String
    8.     Dim lngMinutes As Long
    9.     Dim lngSeconds As Long
    10.  
    11.     lngMinutes = plngSeconds \ 60
    12.     lngSeconds = plngSeconds Mod 60
    13.     SecondsToTime = lngMinutes & ":" & Format(lngSeconds, "00")
    14. End Function
    You say you want the time displayed in "00:00" format, but do you really want a leading zero? The above code assumes you don't. If you do, change the last line in the SecondsToTime() function to this:

    SecondsToTime = Format(lngMinutes, "00") & ":" & Format(lngSeconds, "00")
    Last edited by Ellis Dee; May 30th, 2008 at 10:04 PM.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2007
    Location
    Canada
    Posts
    297

    Re: Little bit of math and VB6

    Great! Thank you very much.

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Little bit of math and VB6

    Now that we've helped you, you can help us by pulling down the Thread Tools menu and clicking the Mark Thread Resolved button which will let everyone know that you have your answer. Also if someone has been particularly helpful you have the ability to affect a their forum "reputation" by rating their post.

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