Re: catch Media Player Error
For a start, all your Trim calls are pointless. You know for a fact that none of the values you've defined has leading or trailing spaces so why do you need to Trim them? The file extensions are in the same boat. If a file extension has leading or trailing spaces then it's not a valid file extension.
Also, your code is way longer than it needs to be. You don't need to identify what a file extension is, just whether it's valid or not. As such you can just put all the extensions in an array and then use a single line to check whether the array contains the current extension.
As for the question, you're already handling exceptions so catch the appropriate type of exception that is thrown when an invalid file type is used and then do whatever's appropriate.
Re: catch Media Player Error
But sir i have to get the extension of the file na
sExtension = IO.Path.GetExtension("sFileName")
And then check that extension in array,But i dont want using extension method,Is there any other way Round......
I know my code is longer way,But sir using if statements will take less than searching elements in array.Isn't so?Or I m wrong???
Re: catch Media Player Error
Since i get no anwer, I follow jmcilhinney suggestion...
Code:
Public Class Form2
Public ExtensionsArrayList As New ArrayList
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call LoadExtensionsToArrayList()
End Sub
Private Sub LoadExtensionsToArrayList()
Try
ExtensionsArrayList.Add(Ext_bmp)
ExtensionsArrayList.Add(Ext_gif)
ExtensionsArrayList.Add(Ext_jpeg)
ExtensionsArrayList.Add(Ext_jpg)
ExtensionsArrayList.Add(Ext_wma)
ExtensionsArrayList.Add(sExe_asx)
ExtensionsArrayList.Add(sExe_wax)
ExtensionsArrayList.Add(sExe_m3u)
ExtensionsArrayList.Add(sExe_wpl)
ExtensionsArrayList.Add(sExe_wvx)
ExtensionsArrayList.Add(sExe_wmx)
ExtensionsArrayList.Add(sExe_searchms)
ExtensionsArrayList.Add(sExe_dvrms)
ExtensionsArrayList.Add(sExe_mid)
ExtensionsArrayList.Add(sExe_rmi)
ExtensionsArrayList.Add(sExe_midi)
ExtensionsArrayList.Add(sExe_mpeg)
ExtensionsArrayList.Add(sExe_mpg)
ExtensionsArrayList.Add(sExe_m1v)
ExtensionsArrayList.Add(sExe_m2v)
ExtensionsArrayList.Add(sExe_mod)
ExtensionsArrayList.Add(sExe_mp2)
ExtensionsArrayList.Add(sExe_mpa)
ExtensionsArrayList.Add(sExe_mpe)
ExtensionsArrayList.Add(sExe_ifo)
ExtensionsArrayList.Add(sExe_vob)
ExtensionsArrayList.Add(sExe_wav)
ExtensionsArrayList.Add(sExe_snd)
ExtensionsArrayList.Add(sExe_au)
ExtensionsArrayList.Add(sExe_aif)
ExtensionsArrayList.Add(sExe_aifc)
ExtensionsArrayList.Add(sExe_aiff)
ExtensionsArrayList.Add(sExe_wmv)
ExtensionsArrayList.Add(sExe_wmd)
ExtensionsArrayList.Add(sExe_avi)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sExtension As String
sExtension = IO.Path.GetExtension("sFileName")
If CheckWhetherExtValid(sExtension) Then
WindowsMediaPlayer.URL = "sFileName"
Else
WindowsMediaPlayer.URL = FOLDER_IMAGES & "\PlayListImage.jpg"
End If
End Sub
Private Function CheckWhetherExtValid(ByVal sExtension As String) As Boolean
Try
Dim lCount As Integer
CheckWhetherExtValid = False
For lCount = 0 To ExtensionsArrayList.Count - 1
If Trim(ExtensionsArrayList.Item(lCount).ToString) = Trim(sExtension) Then
CheckWhetherExtValid = True
Exit For
End If
Application.DoEvents()
Next
Catch ex As Exception
MsgBox(ex.Message)
CheckWhetherExtValid = False
End Try
End Function
End Class
Re: catch Media Player Error
I already answered your question. You just didn't read it:
Quote:
As for the question, you're already handling exceptions so catch the appropriate type of exception that is thrown when an invalid file type is used and then do whatever's appropriate.
If an invalid file is opened an exception will be thrown. Handle that exception.
Re: catch Media Player Error
Sir if file is invalid,no exception is thrown,control doesn't go in Catch block....I want that control goes to catch block..so i set the default image there & there is no need to check extensions....