Solved

Kill statement and MediPlayer control

Posted on 2000-03-23
15
188 Views
Last Modified: 2010-05-02
Hi ,
I have a problem that I can't solve myself.

I am using the Adodc control and a DataGrid control.
For each record in the database belongs a wav file.
and when I move from one record to another, the Mediaplayer filename property changes to the correct wave file.

when I delete recored in the Grid, I'd like that the wave file that belongs to that record, will be deleted from the hard disk as well.
so I used the statment Kill ,and gave the path of the file to be deleted.
an error no. 75 was showed.

I guess the problem is because of that I'm trying  to delete a file that the FileName property of the  MediaPlayer control is set to.

I wish you can help me with that .
Thanks
0
Comment
Question by:kukiya
  • 8
  • 4
  • 3
15 Comments
 
LVL 14

Accepted Solution

by:
mcrider earned 20 total points
ID: 2648763
Before you kill the file, Do this:

   MediaPlayer1.filename = ""
   Kill "c:\windows\desktop\testme.wav"


Cheers!®©
0
 
LVL 3

Expert Comment

by:Gordonp
ID: 2649325
you may also need to call a Close function of something similar.

ie

MediaPlayer1.Close

before you can delete the file

Gordon
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2649389
Gordonp,

There is no "Close" property for MediaPlayer (MSDXM.OCX)... ;-)

All you have to do is set the filename property to ""


Cheers!®©
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

Author Comment

by:kukiya
ID: 2649454
Hi there,
I'm sorry but the error no.75 was still showing even by setting the Filename to "" before the Kill statement.

0
 
LVL 3

Expert Comment

by:Gordonp
ID: 2649524
I've just tried to recreate it here.

when .Filename was still the name of the file

I got error 70 , permission denied.

what I'd expect really

when .Filename = ""

the file deleted OK

I think something else may be causing your error

Gordon

0
 
LVL 14

Expert Comment

by:mcrider
ID: 2649568
This works perfect on my system...

Is the wav still playing when you do this?? If so, stop the wav with:

   MediaPlayer1.Stop
   MediaPlayer1.filename = "" 
   Kill "c:\windows\desktop\testme.wav"


You may also have to do a DoEvents... Like this:


   MediaPlayer1.Stop
   MediaPlayer1.filename = ""
   DoEvents
   Kill "c:\windows\desktop\testme.wav"


You may also want to enforce an error handler... Something like this:
   Dim lRetry As Integer

   MediaPlayer1.Stop
   MediaPlayer1.filename = ""
   On Error Resume Next
   lRetry = 0
   Do
       Err = 0
       DoEvents
       Kill "c:\windows\desktop\testme.wav"
       If Err = 0 Or lRetry = 5 Then Exit Do
       lRetry = lRetry + 1
   Loop



Cheers!®©
0
 
LVL 3

Expert Comment

by:Gordonp
ID: 2649605
kukiya >
   post the record/file deletion code and we'll see if theres anything obvious in that

Gordon
0
 

Author Comment

by:kukiya
ID: 2658132
Here is my code:

Private Sub dgdEvents_BeforeDelete(Cancel As Integer)

Dim response As String
response = MsgBox("Are you sure you want to delete current event?", vbYesNo + vbQuestion, "Confirm Event Delete")

       If response = vbYes Then
          Cancel = False
          DeleteWavPath = txtPath.Text
          Call DeleteWavFile
        End If
           
Private Sub DeleteWavFile()
Dim response As String
   If Dir(DeleteWavPath) <> "" Then the
      response = MsgBox("Do you wish    
      to delete event's audio file  
      too?", vbYesNo +  
      vbQuestion, "Confirm Event    
      Delete")

       If response = vbYes Then
                   
          MediaPlayer1.FileName = ""
          Kill DeleteWavPath
       End If
    End If
End Sub
 
DeleteWavPath is a golbal variable that contains the Path of the wav file to be deleted.The Path is shown in the TextBox txtPath.

I hope that can help more.
Thank you very much!!!!!!!!
           
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2658304
I don't see anything wrong with the code except the "End Sub" is missing on the dgdEvents_BeforeDelete subroutine.

What version of VB are you using?? If you are using VB5/VB6 Do you have Service Pack 3 (SP3) installed? If you don't have SP3 installed, Go to this microsoft link:

INFO: Visual Studio 97 Service Packs - What, Where, and Why
http://support.microsoft.com/support/kb/articles/Q170/3/65.ASP 



What version of Media Player are you using??  If you don't have Version 6.4, download it from here:

Windows Media Player
http://www.microsoft.com/windows/mediaplayer/en/default.asp?RLD=58 



Cheers!®©
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2658313
By the way, "Call DeleteWavFile" is redundant... You don't need to use the "Call" keyword...

One other question... You haven't opened the wav file as a file someplace else, or have more than 1 MediaPlayer control do you??

Cheers!®©
       
0
 

Author Comment

by:kukiya
ID: 2659737
Thank's for you trying to help.

I am using the VB6 and already installed the SP3.
everything seems to be ok with the versions.

I don't know what the problem is.
THANK YOU!!!!!!

0
 
LVL 14

Expert Comment

by:mcrider
ID: 2661223
What about your version of Media Player...
0
 

Author Comment

by:kukiya
ID: 2662954
I also installed the MediaPlayer Version 6.4, though I don't know how to verify that it was dowloaded correctly.


0
 
LVL 14

Expert Comment

by:mcrider
ID: 2664877
Well, this is a stumper, because you seem to have the correct version of everything... and I don't see any problems with the code you posted... SO... Lets go back to basics...


1) Copy a WAV to c:\windows\desktop\testme.wav

2) Start a new project and add 2 Command buttons called "Command1" and "Command2".  Then add MediaPlayer1 control to the form.

3) Add the following code to the declarations section of the form:

    Private Sub Command1_Click()
    MediaPlayer1.filename = "c:\windows\desktop\testme.wav"
    End Sub
    Private Sub Command2_Click()
       MediaPlayer1.Stop
       MediaPlayer1.filename = ""
       Kill "c:\windows\desktop\testme.wav"
    End Sub


4) Run the program and click command1... The mediaplayer should play the sound you copied to the desktop...

5) Click command2... The WAV file you copied to the desktop should be deleted.



If you follow the steps above EXACTLY, everything should work.  If it doesn't work, there is a much bigger problem with your system...


Cheers!®©

0
 
LVL 14

Expert Comment

by:mcrider
ID: 2664879
By the way... This is alot of work for 20 points...
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Visual Basic Excel Formatting error 4 127
How does CurrentUser work? 10 38
VB6 - Compare and highlight cell not the same 3 53
Recommendation vb6 to vb.net or others 14 175
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question