We help IT Professionals succeed at work.

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

p-plater
p-plater asked
on
57 Views
Last Modified: 2015-11-27
I'm missing something basic but I can't work it out..

I have a Public Class with a Public Function inside it (This is in a BLL DLL)

Public Class CompanySearch
    Public Function Search(ByVal searchText As String) As CompanyName
        Dim companySearchList As New CompanyNameCollection(searchText, False)

        If companySearchList.Count = 1 Then
            Dim company As CompanyName = companySearchList.Item(0)
            Return company
        Else
            Using CompanySearchForm = New CompanySearch()
                With CompanySearchForm
                    .SearchTextBox.Text = searchText
                    .SearchResultDataGridView.DataSource = companySearchList
                    .ShowDialog()
                End With
                Dim company As CompanyName = companySearchList.Item(0)
                Return company
            End Using
        End If
    End Function
End Class

Open in new window


I am trying to call it from the UI

Dim company As New CompanyName
company = CompanySearch.Search(CompanyNameTextBox.Text)

Open in new window


But I am getting the "Reference to a non-shared member requires an object reference" Error.
I thought I was giving it an Object Reference by using a Instance of the CompanyName Class?
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2015
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Is there any Serious Security Problem with declaring Class Methods as Shared?

Author

Commented:
Thanks

I thought I had created an instance of the Class - But I was using a different Class :(
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2015

Commented:
Is there any Serious Security Problem with declaring Class Methods as Shared?
Not that I am aware of. Why would you think there would be?
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.