-
Sep 30th, 2020, 11:10 AM
#1
Thread Starter
PowerPoster
[RESOLVED] Access denied.
Hi,
I am trying to open an MP3 track to play. The file path is selected via a FolderBrowserDialog.
Code:
Dim filePath As String, playList As List(Of String)
Private Sub MakeTracks()
Dim trackIn As String
FileOpen(1, filePath, OpenMode.Input)
While Not EOF(1)
trackIn = LineInput(1)
playList.Add(trackIn)
End While
FileClose(1)
End Sub
When I run this subroutine I get an error message:
"Access to the path 'D:\Music\Lonnie Donnegan' is denied."
I don't know how to fix this.
Poppa
Along with the sunshine there has to be a little rain sometime.
-
Sep 30th, 2020, 11:18 AM
#2
Re: Access denied.
If you run Visual Studio as an administrator do you have the same issue?
-
Sep 30th, 2020, 11:23 AM
#3
Re: Access denied.
Originally Posted by Poppa Mintin
Hi,
I am trying to open an MP3 track to play. The file path is selected via a FolderBrowserDialog.
Code:
Dim filePath As String, playList As List(Of String)
Private Sub MakeTracks()
Dim trackIn As String
FileOpen(1, filePath, OpenMode.Input)
While Not EOF(1)
trackIn = LineInput(1)
playList.Add(trackIn)
End While
FileClose(1)
End Sub
When I run this subroutine I get an error message:I don't know how to fix this.
Poppa
If filePath does indeed contain a path to a folder and not to a file, then your code makes no sense. That's not at all how you enumerate the contents of a folder, which appears to be your goal.
The access denied is a bit misleading, but it's because you are trying to treat a folder as a file and open the folder as a file, which will never work.
-
Sep 30th, 2020, 11:27 AM
#4
Re: Access denied.
Originally Posted by Poppa Mintin
Hi,
I am trying to open an MP3 track to play. The file path is selected via a FolderBrowserDialog.
Code:
Dim filePath As String, playList As List(Of String)
Private Sub MakeTracks()
Dim trackIn As String
FileOpen(1, filePath, OpenMode.Input)
While Not EOF(1)
trackIn = LineInput(1)
playList.Add(trackIn)
End While
FileClose(1)
End Sub
When I run this subroutine I get an error message:I don't know how to fix this.
Poppa
Windows has a built-in musical taste filter and will protect you from undesirable content. "Lonnie Donnegan" ... :-)
Seriously though, are you sure your path is to a file and not the folder?
-
Sep 30th, 2020, 11:29 AM
#5
Re: Access denied.
Looks to me that filePath actually would contain a path to a file (or should) that then contains a list of files - sort of like a playlist.
But it'll fail if either filePath or anything in that file is incomplete... since you didn't note where the error happens... we're jsut guessing and shooting in the dark here.
-tg
-
Sep 30th, 2020, 11:30 AM
#6
Re: Access denied.
Also, if in fact it is supposed to read in a file, this isn't the way I'd do it... but eh...
-tg
-
Sep 30th, 2020, 11:36 AM
#7
Thread Starter
PowerPoster
Re: Access denied.
Thanks guys,
I should've spotted that.
Poppa
Along with the sunshine there has to be a little rain sometime.
-
Sep 30th, 2020, 12:21 PM
#8
Thread Starter
PowerPoster
Re: Access denied.
Hmmm...
Still in trouble:
vb.NET Code:
Dim filePath As String, playList As List(Of String)
Private Sub MakeTracks()
Dim trackIn As String
' Get all files from folder.
For Each i In My.Computer.FileSystem.GetFiles(filePath,
FileIO.SearchOption.SearchTopLevelOnly, "*.mp3")
trackIn = My.Computer.FileSystem.GetName(i)
playList.Add(trackIn)
Next
End Sub
When I run this code, at (snippet) Line 8, the string variable 'trackIn' =
"Battle Of New Orleans - Lonnie Donnegan.mp3".
Then at line 9 I get the error:
"Object reference not set to an instance of an object."
This on the first iteration of the loop. I'm only trying to add a string to a list of string.
What's wrong now ?
Poppa
Last edited by Poppa Mintin; Sep 30th, 2020 at 12:26 PM.
Along with the sunshine there has to be a little rain sometime.
-
Sep 30th, 2020, 12:25 PM
#9
Re: Access denied.
Do you have option strict on?
If you put a breakpoint on the line that starts what is the value of i?
-
Sep 30th, 2020, 12:29 PM
#10
Re: Access denied.
Take a look at PlayList. You declared it, but you never created it.
You have:
playList As List(Of String)
You need:
playList As New List(Of String)
My usual boring signature: Nothing
-
Sep 30th, 2020, 12:43 PM
#11
Re: Access denied.
Originally Posted by PlausiblyDamp
Do you have option strict on?
If you put a breakpoint on the line that starts what is the value of i?
more importantly, what's the TYPE of i?
-tg
-
Sep 30th, 2020, 12:47 PM
#12
Thread Starter
PowerPoster
Re: Access denied.
Originally Posted by PlausiblyDamp
Do you have option strict on?
If you put a breakpoint on the line that starts what is the value of i?
Option Strict On
Option Explicit On
Obviously a breakpoint at that point will say 'i is not configured', however, one step further and...
Name:xxValue:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxType:
xxxixxxx"D:\Music\Lonnie Donnegan\Battle Of New Orleans - Lonnie Donnegan.mp3": String
Poppa
Along with the sunshine there has to be a little rain sometime.
-
Sep 30th, 2020, 12:53 PM
#13
Thread Starter
PowerPoster
Re: Access denied.
Originally Posted by Shaggy Hiker
Take a look at PlayList. You declared it, but you never created it.
You have:
playList As List(Of String)
You need:
playList As New List(Of String)
Oh dear... That's me being too quick to get things rolling (again)
Obviously all working correctly now.
Thanks Shaggy
Poppa
Along with the sunshine there has to be a little rain sometime.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|