[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Kill statement and MediPlayer control

Posted on 2000-03-23
15
Medium Priority
?
199 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 80 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month20 days, 13 hours left to enroll

865 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