473,326 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Scoping Issues

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

Nov 1 '06 #1
2 1031
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.

<Mi**************@gmail.comwrote in message
news:11**********************@e64g2000cwd.googlegr oups.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

Nov 1 '06 #2
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.

Mi**************@gmail.com wrote:
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
Nov 1 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: David Stockwell | last post by:
Hi, Another of my crazy questions. I'm just in the process of learning so bear with me if you can. I actually ran it.... with two test cases TEST CASE 1: Say I have the following defined:...
4
by: Joel Gordon | last post by:
Hi, When I try and compile the a class containing the following method : public void doSomething() { for (int i=0; i<5; i++) { IList list = new ArrayList(); Console.WriteLine( i /...
9
by: NevilleDNZ | last post by:
Can anyone explain why "begin B: 123" prints, but 456 doesn't? $ /usr/bin/python2.3 x1x2.py begin A: Pre B: 123 456 begin B: 123 Traceback (most recent call last): File "x1x2.py", line 13,...
3
by: morris.slutsky | last post by:
So every now and then I like to mess around with hobby projects - I often end up trying to write an OpenGL video game. My last attempt aborted due to the difficulty of automating game elements and...
17
by: Chad | last post by:
The following question stems from Static vs Dynamic scoping article in wikipedia. http://en.wikipedia.org/wiki/Scope_(programming)#Static_versus_dynamic_scoping Using this sites example, if I...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.