|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Scoping Issuesthe "files" variable, however i'm getting an "object not set to a instance". I want to be able to move to the next record if this "UnauthorizedAccessException" error occurs. Dim files As ReadOnlyCollection(Of String) Dim obj As New WinControl Dim WS As New CollectionWS.CollectionBroker Dim ds As New System.Data.DataSet Dim dt As New System.Data.DataTable Dim dr As System.Data.DataRow Dim Name As String Dim Drive As DriveInfo Dim Dname As String WS.Credentials = System.Net.CredentialCache.DefaultCredentials ds = WS.GetCollectionTypes dt = ds.Tables(0) 'Get Local drive information For Each Drive In System.IO.DriveInfo.GetDrives Dname = Drive.Name For Each dr In dt.Rows Try Name = dr.Item(1) files = My.Computer.FileSystem.GetFiles(Dname, FileIO.SearchOption.SearchTopLevelOnly, "*." & Name) files.GetEnumerator.MoveNext() obj.GetFileProperties(files, Name) Catch ex As IOException Exit For Catch ex As UnauthorizedAccessException 'I want to move to the next record and try to access it files.GetEnumerator.MoveNext() End Try Next Next What it means, is that the exception was thrown on the GetFiles call while
you were trying to assign a value to 'files'. Because an exception was thrown, 'files' never got a value. It is still null. Yet, in your catch, you are trying to use files. Well, you can't, it never got a value, GetFiles failed and the files were never retrieved. <MichaelEvans1***@gmail.com> wrote in message Show quoteHide quote news:1162403587.385738.299030@e64g2000cwd.googlegroups.com... > Please someone tell me what i'm doing wrong here. I trying to access > the "files" variable, however i'm getting an "object not set to a > instance". I want to be able to move to the next record if this > "UnauthorizedAccessException" error occurs. > > Dim files As ReadOnlyCollection(Of String) > Dim obj As New WinControl > Dim WS As New CollectionWS.CollectionBroker > Dim ds As New System.Data.DataSet > Dim dt As New System.Data.DataTable > Dim dr As System.Data.DataRow > Dim Name As String > Dim Drive As DriveInfo > Dim Dname As String > > WS.Credentials = System.Net.CredentialCache.DefaultCredentials > > ds = WS.GetCollectionTypes > dt = ds.Tables(0) > > 'Get Local drive information > > For Each Drive In System.IO.DriveInfo.GetDrives > > Dname = Drive.Name > For Each dr In dt.Rows > Try > Name = dr.Item(1) > files = My.Computer.FileSystem.GetFiles(Dname, > FileIO.SearchOption.SearchTopLevelOnly, "*." & Name) > > files.GetEnumerator.MoveNext() > obj.GetFileProperties(files, Name) > Catch ex As IOException > Exit For > Catch ex As UnauthorizedAccessException > 'I want to move to the next record and try to access it > files.GetEnumerator.MoveNext() > > End Try > Next > Next > The exception is thrown when you try to get the list of files, as you
don't have access to the folder. As you don't get any list of files, you can not move to the next file. MichaelEvans1***@gmail.com wrote: Show quoteHide quote > Please someone tell me what i'm doing wrong here. I trying to access > the "files" variable, however i'm getting an "object not set to a > instance". I want to be able to move to the next record if this > "UnauthorizedAccessException" error occurs. > > Dim files As ReadOnlyCollection(Of String) > Dim obj As New WinControl > Dim WS As New CollectionWS.CollectionBroker > Dim ds As New System.Data.DataSet > Dim dt As New System.Data.DataTable > Dim dr As System.Data.DataRow > Dim Name As String > Dim Drive As DriveInfo > Dim Dname As String > > WS.Credentials = System.Net.CredentialCache.DefaultCredentials > > ds = WS.GetCollectionTypes > dt = ds.Tables(0) > > 'Get Local drive information > > For Each Drive In System.IO.DriveInfo.GetDrives > > Dname = Drive.Name > For Each dr In dt.Rows > Try > Name = dr.Item(1) > files = My.Computer.FileSystem.GetFiles(Dname, > FileIO.SearchOption.SearchTopLevelOnly, "*." & Name) > > files.GetEnumerator.MoveNext() > obj.GetFileProperties(files, Name) > Catch ex As IOException > Exit For > Catch ex As UnauthorizedAccessException > 'I want to move to the next record and try to access it > files.GetEnumerator.MoveNext() > > End Try > Next > Next >
NULL dates show today's date rather than a blank or NULL on form
NewBie start a windows service remotely Trouble with a console app Try Catch Overkill line replacing ideas Write an XML node Looking for online articles/tutorials or good reference books insert data into master detail entry form DropDownList Refuses To Show New SelectedValue |
|||||||||||||||||||||||