|
-
Mar 5th, 2003, 08:38 PM
#1
Thread Starter
Addicted Member
Object reference not set to an instance of an object
Why would I get this error, and how can I stop my program from getting it?
Object reference not set to an instance of an object.
I often get when trying to change the value of a variable.
ex.
[Add MS Outlook Reference]
Code:
Imports Office
.
.
.
Sub SearchHD
Dim Search as Office.FileSearch
Search.FileName = "test" 'I get the Error Here
End Sub
-
Mar 5th, 2003, 08:39 PM
#2
PowerPoster
Because you are trying to use a null object reference. You need to create the object using the new construct:
Code:
Dim Search as New Office.FileSearch()
' or...
Dim Search as Office.FileSearch
Search = New Office.FileSearch()
Last edited by Lethal; Mar 5th, 2003 at 08:44 PM.
-
Mar 6th, 2003, 10:36 AM
#3
Thread Starter
Addicted Member
Originally posted by Lethal
Because you are trying to use a null object reference. You need to create the object using the new construct:
Code:
Dim Search as New Office.FileSearch()
' or...
Dim Search as Office.FileSearch
Search = New Office.FileSearch()
That dosn't work because "New Office.FileSearch" dosn't exsist.
-
Mar 6th, 2003, 11:07 AM
#4
If there is no public New then that usually means that you cannot create the object in that manner. This is an intentional thing the same as a PublicNotCreatable class in VB6. Generally that means that another object or method returns the one in question (FileSearch) and that is the only way you are suppose to be getting one.
-
Mar 6th, 2003, 11:30 AM
#5
Thread Starter
Addicted Member
So how would I use the FileSearch Property then?
-
Mar 6th, 2003, 08:16 PM
#6
I'm not sure, try selecting it and pressing F1 for help. I believe its a class not really a property and I'd imagine that there is another class and/or method that would ahve the return value of type FileSearch and that is how you get it. But I've never used that particular object so I don't know which one that would be.
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
|