Results 1 to 13 of 13

Thread: [RESOLVED] Access denied.

  1. #1

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    Resolved [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.

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    Re: Access denied.

    If you run Visual Studio as an administrator do you have the same issue?
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  3. #3
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: Access denied.

    Quote Originally Posted by Poppa Mintin View Post
    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.

  4. #4
    Fanatic Member
    Join Date
    Aug 2004
    Location
    Essex, UK
    Posts
    750

    Re: Access denied.

    Quote Originally Posted by Poppa Mintin View Post
    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?

  5. #5
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    Re: Access denied.

    Thanks guys,

    I should've spotted that.


    Poppa
    Along with the sunshine there has to be a little rain sometime.

  8. #8

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    Re: Access denied.

    Hmmm...

    Still in trouble:

    vb.NET Code:
    1. Dim filePath As String, playList As List(Of String)
    2.  
    3.     Private Sub MakeTracks()
    4.         Dim trackIn As String
    5.         ' Get all files from folder.
    6.         For Each i In My.Computer.FileSystem.GetFiles(filePath,
    7.                FileIO.SearchOption.SearchTopLevelOnly, "*.mp3")
    8.             trackIn = My.Computer.FileSystem.GetName(i)
    9.             playList.Add(trackIn)
    10.         Next
    11.     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.

  9. #9
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,458

    Re: Access denied.

    Do you have option strict on?

    If you put a breakpoint on the line that starts
    Code:
      For Each i
    what is the value of i?

  10. #10
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    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

  11. #11
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    Re: Access denied.

    Quote Originally Posted by PlausiblyDamp View Post
    Do you have option strict on?

    If you put a breakpoint on the line that starts
    Code:
      For Each i
    what is the value of i?
    more importantly, what's the TYPE of i?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  12. #12

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    Re: Access denied.

    Quote Originally Posted by PlausiblyDamp View Post
    Do you have option strict on?

    If you put a breakpoint on the line that starts
    Code:
      For Each i
    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.

  13. #13

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    Re: Access denied.

    Quote Originally Posted by Shaggy Hiker View Post
    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
  •  



Click Here to Expand Forum to Full Width