Requires Object Reference???? 
Author Message
 Requires Object Reference????

I have a class library that looks like this:

Imports System
Imports System.Data
Imports Microsoft.Data.Odbc
Namespace WEL.MIS.Procedures
Public Class Class1
Public ODBCPipe As OdbcConnection
Public ConnectString As String

Public Sub ConnectIt()
ConnectString = "Some SQL B.S. that doesn't matter for this question"
ODBCPipe = New OdbcConnection(ConnectString)
End Sub

Public Sub DisconnectIt()
ODBCPipe.Close()
End Sub

End Class
End Namespace

OK??  Now then, I have another project that will use this library.  I've set
up the reference in that project and included a "Imports WEL.MIS.Procedures"
statement.  But, my code that calls ConnectIt has a blue squigly line under
the word "ConnectIt" that says "Reference to non-shared member requires
object reference").  How do I fix this?  And what do you call that blue
squigly line?

--
"Programming is 1% inspiration, 99% Help files...."   <- AND
Newsgroups....;-)
----------------------------------------------------------------------------
--
Rick Palmer
Systems Developer
W. E. Love and Associates, Inc. C.M.G.A



Mon, 27 Sep 2004 04:21:36 GMT  
 Requires Object Reference????
<snip>

Quote:
> Namespace WEL.MIS.Procedures
> Public Class Class1
> Public ODBCPipe As OdbcConnection
> Public ConnectString As String

<snip>

Quote:
>End Class
> End Namespace

<snip>

Quote:
>  But, my code that calls ConnectIt has
> a blue squigly line under the word "ConnectIt" that says "Reference
> to non-shared member requires object reference").  How do I fix this?
> And what do you call that blue squigly line?

What does your code look like that calls ConnectIt?  Is it something like:

Class1.ConnectIt()  ?

My guess is that you don't have an instance of Class1.  So, something like
this will fix your problem:

Dim MyClassInstance As Class1 = New Class1()
MyClassInstance.ConnectIt()

Your other option is to make your methods shared like so:

Shared Public Sub ConnectIt()
End Sub

Then, Class1.ConnectIt() will work just fine.

Hope this helps.

--
Jacob Grass
Microsoft .NET MVP



Mon, 27 Sep 2004 06:00:43 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. dotnet Reference to non-shared member requires object reference - Global.asax.vb

2. reference to a non-shared member requires an object reference

3. Reference to a non-shared member requires an object reference

4. Reference to a non-shared member requires an object reference

5. Passing an object reference by reference where the object has a default property

6. Referencing object in form in code / Subform reference problem in code

7. detecting "object required" or null object

8. detecting "object required" or null object

9. I don't understand the error message: "Reference to a non-shared member requires an object reference" in a class

10. I don't understand error message "Reference to non-shared member requires an object reference"

11. User credentials required while adding web reference

12. User credentials required to add web reference

 

 
Powered by phpBB® Forum Software