PDA

View Full Version : Auto Update (without clicking on scrollbar (on worksheet) every second!



agarwaldvk
03-26-2013, 02:31 PM
Hi Everybody


I have created a MediaPlayer for my own needs - not complete yet but works fine so far.

Important :-
All controls are on the worksheet and not on the form.

I have a scrollbar which, when clicked on, will move the current position of the song to the position of the tracker of the scrollbar. when this scrollbar is clicked on, I can also get it to display (in a separate textbox) of the current postion in time units and move this display of time along the scrollbar - no problems. What I need is to be able to do is get the scrollbar to take the value of the current position of the song and move the tracker corresponding changing every second WITHOUT HAVING TO CLICK on the scrollbar - as we see on the built-in media player/wiinamp interface. I believe that a stopwatch kind of code alongwith the 'worksheet_change' event would do the job - correct me if I am wrong.

I found this code on this forum's knowledge base. This is fine but I am not able to use this in my application as is - I need some help here to be able to use this code.

Can someone suggest what modifications do I need to make so that

Public stopMe As Boolean
Public resetMe As Boolean
Public myVal As Variant
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Column = 1 Then
If Target.Value = myVal And Target.Value <> "" Then
'Changed
Dim startTime, finishTime, totalTime, timeRow
startTime = Timer
stopMe = False
resetMe = False
myTime = Target.Offset(, 2).Value
Target.Offset(, 1).Select
startMe:
DoEvents
timeRow = Target.Row
finishTime = Timer
totalTime = finishTime - startTime
Target.Offset(, 1).Value = Format(myTime + totalTime, "0.0000") & " Seconds"
If resetMe = True Then
Target.Offset(, 1).Value = 0
Target.Offset(, 2).Value = 0
stopMe = True
End If
If Not stopMe = True Then
Target.Offset(, 2).Value = totalTime
Goto startMe
End If
Cancel = True
End
Else
'Not Changed
stopMe = True
Cancel = True
End If
End If
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
myVal = Target.Value
End Sub



Best regards



Deepak