Reference to a non-shared member requires an object reference occurs when calling public sub
Asked Answered
L

2

31

I have a Public Class "General" in which is a Public Sub "updateDynamics". When I attempt to reference it in the code-behind for a page like so:

updateDynamics(get_prospect.dynamicsID)

I get the following error:

reference to a non-shared member requires an object reference

Liesa answered 19/11, 2012 at 21:22 Comment(0)
B
48

You either have to make the method Shared or use an instance of the class General:

Dim gen = New General()
gen.updateDynamics(get_prospect.dynamicsID)

or

General.updateDynamics(get_prospect.dynamicsID)

Public Shared Sub updateDynamics(dynID As Int32)
    ' ... '
End Sub

Shared(VB.NET)

Bushhammer answered 19/11, 2012 at 21:24 Comment(1)
Thanks, that is exactly what I needed. I had tried doing instances, but was attempting to do an instance of updateDynamics, instead of realizing that updateDynamics would be a method of General.Liesa
G
1

Go to the Declaration of the desired object and mark it Shared.

Friend Shared WithEvents MyGridCustomer As Janus.Windows.GridEX.GridEX

Grecian answered 20/11, 2015 at 12:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.