1

Is there a way for me to just specify an event handler without creating a new sub?

For example... Normally I would do something like the following:

AddHandler btn.click, EventHandler OpenDirectory

Private Sub OpenDirectory
     Process.Start("SomeDir")
End Sub

As you can see, the sub is just a one line of code. So, can I simplify it down and do something like the following:

AddHandler btn.click, Process.Start("SomeDir")

I know the above doesn't work, but I'm hoping I'm being clear in what I want to do with the example.

gCanuck
  • 39
  • 1
  • 6
  • 2
    Use an in-line one: `AddHandler btn.Click, Sub(snd, evt) Process.Start("SomeDir")`. It can substitute an explicit `EventHandler` (you don't even need the parameters). Also see: [Lambda Expressions](https://learn.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/procedures/lambda-expressions). – Jimi Aug 01 '18 at 16:34
  • Make sure you remove that handler as well. – Trevor Aug 01 '18 at 16:48
  • 1
    Wonderbar! Thanks. Learn something new everyday. – gCanuck Aug 01 '18 at 16:53

0 Answers0