0

In our VB.NET code, we are using many event handlers.

For below line of code we are getting the syntax error "BC30469 Reference to a non-shared member requires an object reference" where we use an optional parameter in the function signature:

AddHandler TabControl.Click, AddressOf FrmMW.ProcessTabClickEvent

where the function signature is

Public Sub ProcessTabClickEvent(sender As System.Object, e As System.EventArgs, Optional OpenNewTab As Boolean = False)

But for the below case, i.e. without optional parameters, we are not getting the syntax error:

AddHandler menuItem.Click, AddressOf SelectAllAction

where the function signature is

Private Sub SelectAllAction(ByVal sender As Object, ByVal e As EventArgs)

Please assist in solution. Our code is getting built successfully in VB Express 2010, but we are getting this error in VB Express 2017.

GSerg
  • 76,472
  • 17
  • 159
  • 346
IT researcher
  • 3,274
  • 17
  • 79
  • 143
  • 1
    Does this help? https://stackoverflow.com/questions/13401246/how-to-pass-parameters-in-addhandler-using-vb-net – Zaid Al Shattle Sep 30 '21 at 11:11
  • 1
    The error you are getting has nothing to do with the parameter and everything to do with `AddressOf SelectAllAction` vs `AddressOf FrmMW.ProcessTabClickEvent`. I assume `FrmMW` is the name of the class, as opposed a variable holding an instance of that class. – GSerg Sep 30 '21 at 11:16
  • 1
    Incidentally, instead of using an optional parameter, you could create your own class for the event data as shown in the example in [EventArgs Class](https://learn.microsoft.com/en-us/dotnet/api/system.eventargs). – Andrew Morton Sep 30 '21 at 12:20
  • @GSerg Do you know why it affects only when we try to build the code in VB express 2017 and not in VB express 2010 ? In VB express 2010, we are able to build successfully without any syntax errors. – IT researcher Oct 01 '21 at 05:42
  • I don't know. Could be because you [disabled implicit instancing](https://stackoverflow.com/a/49951582/11683) in there somehow? – GSerg Oct 01 '21 at 06:53

0 Answers0